专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java Exception

抛异常时的一些异常

发布时间:2010-06-05 12:36:41 文章来源:www.iduyao.cn 采编人员:星星草

抛异常:

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有关系么?


------解决方法--------------------------------------------------------
if(i != 0) //现在你设定的是零
throw new Exception("sadlfj"); //所以这条语句不执行
 

    
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: