There are return statements in the try statement block and catch statement block, but there is no return statement in the finally statement block, and there is an exception .
The code is as follows:
publicclassMain{publicstaticvoidmain(String[]args){System.out.println(test3());}publicstaticinttest3(){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);}}}
The running results are as follows:
try statement catch statement finally statement 9
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, execute return in the catch block.