异常处理:抛出多个异常

2020-09-28  本文已影响0人  雨景江水

一.
注:不可能的,TRY CATCH里面主动抛出多个异常,从第二个异常起编译就不通过,

try {

        throw new Exception("抛出异常1");
        throw new Exception("抛出异常1");    //这里编译通不过

} catch (Exception e1) {
e1.printStackTrace();
System.out.println("捕获异常");
}

二.
因为try语句块里面,出现了异常,try语句块下面的代码就不执行了

int a = 11;
int b = 0;
try {
int x = a/b;
System.out.println(x);
throw new Exception("抛出异常1");

} catch (Exception e1) {
e1.printStackTrace();
System.out.println("捕获异常");
}

上一篇 下一篇

猜你喜欢

热点阅读