The only times finally
won‘t be called are:
- If you call
System.exit()
- If the JVM crashes first
- If there is an infinite loop in the
try
block - If the power turns off
以上来自:Does finally always execute in Java?
另见Sun Tutorials中的note:
Note: If the JVM exits while the
try
or catch
code is being executed, then the finally
block may not execute. Likewise, if the thread executing the try
or catch
code is interrupted or killed, the finally
block may not execute even though the application as a whole continues.
时间: 2024-10-27 11:16:44