java吧 关注:1,292,132贴子:12,824,645
  • 3回复贴,共1

求大神解释????????

只看楼主收藏回复

public class Exception {
public static void main(String[] args){
int[] arr = {1,2,3,4};
try{
System.out.println(arr[5]);
System.out.println(2/0);
}catch(ArrayIndexOutOfBoundsException e){
e.printStackTrace();
System.out.println("程序维护中");
}catch(ArithmeticException e){
e.printStackTrace();
System.out.println("死机了");
}
}
}
try后面两条代码都错了,但是只提醒了第一个的错误。


IP属地:江苏1楼2015-11-17 14:34回复
    只要捕获第一个错误,剩下的代码都不会执行。


    IP属地:云南来自Android客户端2楼2015-11-17 14:39
    收起回复
      2025-12-22 06:41:31
      广告
      不感兴趣
      开通SVIP免广告
      下面那一句不会执行,上面抛出错误然后执行catch去咯!


      IP属地:湖北来自Android客户端3楼2015-11-17 15:19
      回复