finally in exception handling

后端 未结 8 1621
甜味超标
甜味超标 2021-01-18 17:08

What exactly does a finally block in exception handling perform?

相关标签:
8条回答
  • 2021-01-18 18:00

    It executes no matter if you get into the catch block or not, meaning that is a great place for disposing of objects and doing other cleanups.

    0 讨论(0)
  • 2021-01-18 18:01

    finally keyword is used just to make sure that code present in finally block must execute in all circumstances irrespective of exception occurances.

    for eg:

     try{
         }
         catch(Exception e){
         }
          finally{
                 System.out.print("finally executed");
                }
    

    Note: In above case finally will always execute.

    0 讨论(0)
提交回复
热议问题