Does a finally block always get executed in Java?

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

    finally will execute and that is for sure.

    finally will not execute in below cases:

    case 1 :

    When you are executing System.exit().

    case 2 :

    When your JVM / Thread crashes.

    case 3 :

    When your execution is stopped in between manually.

提交回复
热议问题