Why do we use finally blocks?

前端 未结 11 2333
甜味超标
甜味超标 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:31

    finally block in java can be used to put "cleanup" code such as closing a file, closing connection etc.


    The finally block will not be executed if program exits(either by calling System.exit() or by causing a fatal error that causes the process to abort).

提交回复
热议问题