Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

try ,catch, finally execution [duplicate]

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 executed always after the try(-catch) block, if an exception is thrown or not.

My question is IF I got Exception in finally block than how to handle it ?????

like image 923
Hardik Nadiyapara Avatar asked Dec 26 '22 19:12

Hardik Nadiyapara


1 Answers

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

like image 75
Tassos Bassoukos Avatar answered Jan 14 '23 02:01

Tassos Bassoukos