Exception handling mechanism in the finally clause

Use Background: Regardless of whether an abnormality exists or is being captured, we want to execute some code;

grammar:

try{
   statements1;
  
statements2;
  statements3;
}
catch(TheException ex){
handing ex;
}
finally{
statements4;
}
statements5;

In any case, the finally block of code will be executed, without the try block is abnormal or whether captured;

Consider the following three cases may arise:

  • If there is no abnormality in the try block
  • If there is a try block statement causes abnormalities, and catch block catches
  • If there is a try block statement causes abnormal, is not captured any time catch block
  1. Statements1 execution statement in the try block, the finally block statments4, the try block codes remaining statements2, statements3;
  2. statments1 statement and abnormal captured catch block is skipped and the execution of a catch statements3 statements2 and finally block code, and then the next statement in the try block;
  3. Skip statements in the try block, the finally exception statement and transferred to the caller of this method;

 

Guess you like

Origin www.cnblogs.com/j2eewsm/p/11263007.html