Does a finally block always get executed in Java?

前端 未结 30 1548
逝去的感伤
逝去的感伤 2020-11-21 07:24

Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is?

try         


        
30条回答
  •  孤街浪徒
    2020-11-21 07:26

    Concisely, in the official Java Documentation (Click here), it is written that -

    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.

提交回复
热议问题