Try, catch, finally execute

Possible duplicate:
throws Exception in finally blocks

  • The catch block is only executed if an exception is thrown in the try block.

  • The finally block is always executed after the try (-catch) block if an exception is thrown.

My IF question I got an Exception at the end of the block, how to handle it ?????

+4
source share
2 answers

This is a well-known / gotcha problem in the Java language specification, in the sense that if an exception is thrown in the finally clause (without processing it in a nested try-catch), the original exception will be lost. You will need to attach a new try-catch in order to catch the new exception and handle it there.

+7
source

You must handle the Exception in the finally block

as

finally{ try { /// } catch(Exception e) { /// } } 
+3
source

All Articles