java - Without using finally, how can we execute any statement even after exception is thrown? -


without using finally, how can execute compulsory statement after exception thrown ?? furthermore, variables used or method has scope inside try block. question asked me in interview. please suggest answer.

try{     //........ statement 1     // ....... statement 2 might throw exception     // ....... statement 3  - compulsory statement                              needs executed if exception thrown.     }  catch {   } 

this academic - if want statement executed after exception thrown, should use finally. however, could catch exception in try-catch-block, put statement inside catch clause, , rethrow exception. emphasis on could, of course should not.

/*  * not this! (even if could.)  */ try {     //........ statement 1     exception e = null;     try {         // ....... statement 2 might throw exception     } catch (exception e2) {         e = e2;     }     // ....... statement 3  - compulsory statement     //                         needs executed if exception thrown.      if (e!=null) {         throw e;     } } catch {  } 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -