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.

 

相关文章:

  • 2021-10-26
  • 2021-09-10
  • 2022-02-06
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
  • 2021-11-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2021-07-02
  • 2021-09-11
相关资源
相似解决方案