栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

异常处理 1.04

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

异常处理 1.04

基本概念
  1. 是程序中的不正常事件,不包括语法错误和逻辑错误
  2. Error(错误):Java虚拟机不能解决严重问题
  3. Exception(异常):外在因素或编译错误一般性问题
  4. 异常分运行时异常(可以不处理)和编译时异常(必须处理)
异常体系图

五种常见运行时异常
public class Exception00 {
    public static void main(String[] args) {
        //no1
        Integer[] integers = new Integer[3];
        integers[4] = 4;
        //no2
        System.out.println(1 / 0);
        //no3
            A b =   new B();
            B b2 = (B)b;
            C c = (C)b;
        //no4
        String a = null;
        System.out.println(a.length());
        //no5
        String  name = "smith";
        int i = Integer.parseInt(name);
        System.out.println(i);

    }
}
class A{}
class B extends A{}
class C extends A{}
处理异常

throws

try - catch (ctrl + alt + j)

public class Throws_ {
    public static void main(String[] args) throws Exception{
        try {
            System.out.println(1 / 0);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            System.out.println("!!!");
        }
    }
}
        System.out.println("!!!");
    }
}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/697437.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号