What is the purpose of the finally clause of a try-catch-finally statement

The finally clause is used to provide the capability to execute code no matter whether ornot an exception is thrown or caught.

Showing Answers 1 - 4 of 4 Answers

anubhav

  • Sep 15th, 2005
 

yes basic purpose of finally clause is same but it is not always true it will execute every time specially when there is System.exit either in try or catch clause dealing with try clause exception

  Was this answer useful?  Yes

In try,catch clauses either try clause(If exception is not happend) or catch clause(If exception occures) is exicuted.If we want to exicute a block of statements doesn't depend on exception then we put those block of statements in finally block.

i.e finally block execution doesn't depend on the exception.If exception doesn't occur then "try ,finally " clauses other wise "catch  , finally" will be exicuted.

ThankU
Ashok

  Was this answer useful?  Yes

Kingsley

  • Jan 24th, 2012
 

You dont need the "finally" clause. Leave it out altogether, and the same thing happens - the code will get executed anyway. The "finally" clause is irrelevant.

  Was this answer useful?  Yes

Tushar

  • Feb 9th, 2012
 

when we write try catch block, at that time we try block caught an exception in this case we must & should want to execute some peace of code at that time we write this code in finally block . finally block must & should be executed at the End

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions