抛异常时的一些异常~~~

binsolove binsolove 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
public class ExceptionTest {

public static Integer i = 0;

public static void main(String[] args) throws Exception{
try{
if(i != 0)
throw new Exception("sadlfj");

}catch(NullPointerException e){
System.out.println("Caught NullPointerException111");
}finally{
System.out.println("Got through new");
}

try{
i = 10;
System.out.println(i.toString());
}catch(NullPointerException e){
System.err.println("Caught NullPointerException222");
}finally{
System.out.println("Got through it");
}
}

}
输出结果:
Got through new
10
Got through it

我觉得如果没有在第一个try块中没有抓住异常,就不应在执行第二个try块啊,但是为什么第二个try块也执行了???和finalize有关系么?
...全文
评论 13
收藏 已收藏
分享
返回顶部
binsolove
Java SE 62,620 成员 307,251 内容