您的位置:首页 > 其它

try--catch语句的catch问题

2013-09-28 22:57 204 查看
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要捕获的异常量是同一种异常或者存在继承关系,则要将捕获子异常放在语句最前面 ,否则编译报错
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐