快捷导航

下面两个列子异常抛出后是否执行?

①这个例子抛出异常后 System.out.println("执行");  不会执行
public static void main(String[] args)throws Exception {
String str = null ;
                int strLength = 0;
                strLength = str.length();
                System.out.println(strLength);
System.out.println("执行");
}
②这个例子抛出异常后 System.out.println("执行");  会执行
public static void main(String[] args)throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy,MM,dd");
       
Date date1 = sdf.parse(strTime);

                System.out.println("执行");
}


问题:为啥都是抛出异常,大家都没有处理异常,但是一个会执行一个不会执行啊?求教大神们

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员1

上面那个是 null=0出现的异常,属于执行后产生的,第二个连 strtime 都没有,代码会直接报错的吧。建议你去看看 Exception 和 error 的区别
回复

使用道具 举报

可能感兴趣的问答

发新帖
  • 微信访问
  • 手机APP