try {normal statement; 1. Exception occurred; 2. return "Try"; } catch (Exception ex) {normal statement; 3. return "Catch"; } finally {normal statement; 4. return "finally"; 5. -->end}
try { normal statement; //1. exception occurred; //2. return "Try"; } catch (Exception ex) { normal statement; //3. return "Catch"; //5. -->End } finally { normal statement; //4. }
try { normal statement; //1. exception occurred; //2. return "Try"; } catch (Exception ex) { normal statement; //3. throw Exception; } finally { normal statement; //4. return "Finally"; //5. -->end }
try { normal statement; //1. exception occurred; //2. return "Try"; } catch (Exception ex) { normal statement; //3. throw Exception; } finally { normal statement; //4. throw Exception; //5. -->end }
try {normal statement; 1. Exception occurred; 2. return "Try"; } catch (Exception ex) {normal statement; 3. Throw Exception; 5. -->end} finally {normal statement; 4. }
Conclusion:
1, try-catch-finally in the end will be executed, and, must take precedence over the Try/catch in the Return/throw statement execution, unless the system collapsed or the program uses System.exit (0) forcibly terminated;
2. If there is return or throw in Finally, the Return/throw in the finally is treated preferentially;
3, return and throw, from the perspective of the statement flow , the two statements are equivalent;
4. There is no return or throw in Finally, then the program goes back to Try/catch to execute the return/throw statement. If the original is catch=>finally, the Return/throw is executed back to the catch, and if it is try=>finally, the Return/throw is executed back to the try and if try/ There is no return/throw in the catch, then the try-catch-finally statement body goes out and executes the subsequent code.
This article is from the "Bitterjava" blog, make sure to keep this source http://rickqin.blog.51cto.com/1096449/1868754
About the execution order of Try Catch finally throw return in Java