Re: Java exception handling process

Following conventional methods:

 1 public int getNum() {
 2         try {
 3             int a = 1/0;
 4             return 1;
 5         }catch (Exception e){
 6             return 2;
 7         }finally {
 8             return 3;
 9         }
10     }

Code encounter came on line 3 when a MathException, then the fourth line of code will not execute the code to jump directly to the catch
statement, went on line 6, when there is such a principle exception mechanism If you encounter a return or abnormality in the function of the catch can then terminated
then there must finally finally block before executing the code inside and then the return value. So the code and jump to line 8, line 8 is a pity that a
return statement, then this method is over time, so the result of the return line 6 would not be true to return. If the deal is finally only an
operation to release the resource, then the result of the questions eventual return is 2. Thus the return value is above 3.

Guess you like

Origin www.cnblogs.com/noperx/p/11360124.html