Condition 1: If there is no exception in try and return in Try (execution order)
tryfinallyreturn
Condition 2: If there is an exception in the try and return in Try
try----catch---finallyreturn
In short, finally always execute!
Condition 3: There is an exception in the try, there is no return in the try-catch-finally, finally there is a return
try----catch---finally
If there is an exception in the try, then execute finally after catch according to the exception mechanism of Java, at this time the error exception has been thrown, the program terminates because of an exception, so your return will not be executed
Condition 4: When there is return in try and finally, the return in finally will overwrite the return of the other position (multiple return will be reported unreachable code, the compilation will not pass).
Condition 5: When return does not exist in finally, and return is present in the catch, but finally in the change value of return in the catch
0;try{ thrownewException();}catch(Exception e){ 1; return ret;}finally{ 2
The last return value is 1, because the return value has been determined before the finally run.
Do you have return,finally in Try Catch finally,try?