Does a finally block always get executed in Java?

前端 未结 30 1585
逝去的感伤
逝去的感伤 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:32

    The finally block is always executed unless there is abnormal program termination, either resulting from a JVM crash or from a call to System.exit(0).

    On top of that, any value returned from within the finally block will override the value returned prior to execution of the finally block, so be careful of checking all exit points when using try finally.

提交回复
热议问题