【发布时间】:2017-02-12 11:20:29
【问题描述】:
catch 块是如何决定的?
try{
int a[]=new int[5];
a[5]=30/0;
}
catch(ArithmeticException e){System.out.println("task1 is completed");}
catch(ArrayIndexOutOfBoundsException e){System.out.println("task 2 completed");}
catch(Exception e){System.out.println("common task completed");}
我只知道派生类在前,基类紧随其后。 ArithmeticException 和 ArrayIndexOutOfBoundsException 类来自:
java.lang.Exception
java.lang.RuntimeException
java.lang.ArithmeticException
和
java.lang.Exception
java.lang.RuntimeException
java.lang.IndexOutOfBoundsException
java.lang.ArrayIndexOutOfBoundsException
为什么ArithmeticException放在第一位?
【问题讨论】:
-
“为什么
ArithmeticException放在第一位?”没有理由。ArithmeticException和ArrayIndexOutOfBoundsException可以按任意顺序排列,只要它们都在Exception之前。