lass ExceptionTest{
public static void main(String args[]){
try{
methodA();
}
catch(IOException e){
System.out.println("caught IOException");
}
catch(Exception e){
System.out.println("caught Exception");
}
}
}
1. If methodA() throws a IOException, what is the result?
答案:caught IOException
2.If we change the sequence of catch,what’s the result?(更换两个catch的顺序,结果如何)
答案:编译错误
Unreachable catch block for IOException. It is already handled by the catch block for Exception
无法到达的catch块IOException异常。他已经被IOException异常的catch块已经被处理、
如果catch要捕获的异常量是同一种异常或者存在继承关系,则要将捕获子异常放在语句最前面 ,否则编译报错