有没有这样的情况,在try-最终块最终不会被执行? [英] Is there such case when in try\finally block the finally won't be executed?

查看:116
本文介绍了有没有这样的情况,在try-最终块最终不会被执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在面向对象编程中进行测试,我想知道是否有任何情况,考虑以下代码:

  try {
do something
} catch(someException e){

} finally {
do something
}

finally 块不会执行?

解决方案

是的。如果您崩溃了Java VM,或者通过本地代码将其丢弃,导致该程序终止,或者无限循环/等待 try 块。



这三种情况只能避免执行 finally 块。


I'm studying for my test in Object Oriented Programming and I was wondering if there is any case what so ever that considering the following code:

try {
    do something
} catch (someException e) {

} finally {
    do something
}

the finally block will not execute?

解决方案

Yes. If you crash the Java VM or otherwise muck things up via native code, cause the program to terminate, or loop/wait infinitely inside the try block.

Those are the only three cases which will avoid executing the finally block.

这篇关于有没有这样的情况,在try-最终块最终不会被执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆