Why do we use finally blocks?

前端 未结 11 2334
甜味超标
甜味超标 2020-11-27 11:43

As far as I can tell, both of the following code snippets will serve the same purpose. Why have finally blocks at all?

Code A:

try { /*          


        
11条回答
  •  醉话见心
    2020-11-27 12:14

    Because you need that code to execute regardless of any exceptions that may be thrown. For example, you may need to clean up some unmanaged resource (the 'using' construct compiles to a try/finally block).

提交回复
热议问题