Why use Finally in Try … Catch

前端 未结 14 2032
鱼传尺愫
鱼传尺愫 2020-12-05 06:38

I see that the Finally in Try .. Catch will always execute after any parts of the execution of the try catch block.

Is it any different to

14条回答
  •  孤街浪徒
    2020-12-05 06:44

    you use finally for cleanup code, eg db connections or files that are open that needs to be close. Virtually any cleanup code that needs to execute regardsless of an exception or not

    also, your exception handling might require to re throw the exception, or other exception, in which case the code after the block will not be executed

提交回复
热议问题