finally是否始终执行

时间:2023-03-10 07:16:47
finally是否始终执行

The only times finally won't be called are:

  1. If you call System.exit()
  2. If the JVM crashes first
  3. If there is an infinite loop in the try block
  4. 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.

相关文章