There are return statements in the try statement block, catch statement block and finally statement block, and there are exceptions .
The code is as follows:
publicclassMain{publicstaticvoidmain(String[]args){System.out.println(test4());}publicstaticinttest4(){inti=10;try{System.out.println(try statement);intj=10/0;return- -i;}catch(Exceptione){System.out.println(catch statement);return--i;}finally{System.out.println(finally statement);return--i;}}}
The running results are as follows:
try statement catch statement finally statement 8
Execution order:
1. First execute the statement in the try block, if an exception occurs, catch the exception.
2. Execute the statements in the catch block, including the expression operation in the return statement, but do not return.
3. Execute all the code in the finally statement block.
4. Finally, I found that there is a return statement in the finally statement block, and return from here.