运行时异常与检查时异常

检查时异常为语法错误或逻辑错误

运行时异常编译器不检查但在执行时会影响后面代码的执行

一.运行时异常分类(RuntimeException):

1.NullPointerException:空指针异常

2.ArithmeticException:数学异常

3.ArrayIndexOutOfBoundsException:数组越界

4.SecurityException:安全异常

5.IllegalArgumentException:非法参数异常

6.ArrayStoreException:数组成员类型异常

7.NegativeArraySizeException:负长度数组

二.异常处理try...catch语句:

public class Fire {
    
    public static void main(String[] args) {
        
        try {
            System.out.println(1/0);
        }catch(Exception t){
            System.out.println(t);//输出错误类型
        }finally {//无论有无错误均会执行
            System.out.println("一定执行");
        }
    }

}

 

 

 

猜你喜欢

转载自blog.csdn.net/SignalFire/article/details/105428399