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要捕获的异常量是同一种异常或者存在继承关系,则要将捕获子异常放在语句最前面 ,否则编译报错
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要捕获的异常量是同一种异常或者存在继承关系,则要将捕获子异常放在语句最前面 ,否则编译报错
相关文章推荐
- 谈论try,catch,语句中的return语句与后面的finally中语句谁先执行的问题
- 黑马程序员 try或catch中存在return 语句时,它们与finally 的执行顺序问题
- try catch finally中return语句与非return语句的执行顺序问题
- RuntimeException的特殊情况&&[C++] 有人会在程序中try catch吗?&&什么样的问题需要用try catch语句执行
- try/catch中有return语句finally是否被执行,什么时候执行?
- try~Catch语句中异常的处理过程
- PHP5的异常处理机制[9]--Try-catch 语句
- 腾讯云图片鉴黄集成到C# SQL Server 怎么在分页获取数据的同时获取到总记录数 sqlserver 操作数据表语句模板 .NET MVC后台发送post请求 百度api查询多个地址的经纬度的问题 try{}里有一个 return 语句,那么紧跟在这个 try 后的 finally {}里的 code 会 不会被执行,什么时候被执行,在 return 前还是后? js获取某个日期
- java try catch finally中的return问题
- try-catch-finally 引发的奇怪问题
- 黑马程序员--Try...catch...finally语句总结
- 描述异常处理语句try、catch、finally执行时的相互关系
- 关于java中的try-catch-finally语句和return
- 真真正正的try_catch_finally语句的最根本的地方 和return .system.exit(0)
- 关于try、catch、finally语句块中含有return语句的几点说明
- try...catch...finally语句块
- 关于JAVA的try catch finally的return返回值问题
- 再次探讨企业级开发中的Try......Catch性能问题
- 关于java的try...catch块中finally语句何时被执行的问题
- try-catch语句讲解