【发布时间】:2020-04-11 23:55:03
【问题描述】:
当我们可以在单个默认异常中处理它时,为什么我们应该使用 多次捕获?
public static void main(String[] args) {
try{
int a[]=new int[5];
a[5]=30/0;
}
catch(ArithmeticException e)
{
System.out.println("Arithmetic Exception occurs");
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("ArrayIndexOutOfBounds Exception occurs");
}
catch(Exception e)
{
System.out.println("Parent Exception occurs");
}
System.out.println("rest of the code");
}
【问题讨论】:
标签: exception nullpointerexception try-catch indexoutofboundsexception arithmeticexception