如果catch块捕获了一个异常,那么finally块还会被调用吗
Java
If an exception is thrown inside a catch block, will the finally block be still be called?
(如果catch块捕获了一个异常,那么finally块还会被调用吗)
YES
同类其他面试题 点击新一篇或旧一篇可浏览全部同类面试题
新一篇:关于Ant的几个面试题
If an exception is thrown inside a catch block, will the finally block be still be called?
(如果catch块捕获了一个异常,那么finally块还会被调用吗)
YES
版权声明:本站大部分内容为原创! 另有少部分内容整理于网络,如需转载本站内容或关切版权事宜请联系站长。未经允许,严禁复制转载本站内容,否则将追究法律责任。 本站欢迎与同类网站建立友情链接,请联系QQ:176687814
不管怎样,有finally 就一定会被执行
下面的情况就不执行
try {
System.exit(0);
} finally {…}
finally will not be executed when:
1. System.exit();
2. In daemon threads. if all other threads exit, daemon thread will stop immediately.
3. No power ~~~
//同意Anonymous君的意见,下面是代码验证。
package cn.xea.exceptions;
public class ZeroException {
public int chuFa(int x,int y){
return x/y;
}
public static void main(String[] args) {
ZeroException zeroex=new ZeroException();
try{
zeroex.chuFa(1, 0);
}catch(Exception e){
System.out.println(“Zero exception!”);
System.exit(0);
}finally{
System.out.println(“thanks,zero!”);
}
}
//结果是不执行finnally语句块。
要是多重异常处理嵌套时,内部嵌套异常的finally子句可能就不执行!
该线程或者该线程没有退出或者死亡的话,finally会执行