Record the try. Catch.. Finally.. In the case of return.
There are no return statements in the return,finally in 1.try.
The following code:--Returns the code in the 1;finally is also executed, but the try in return a program will be recorded 1, after the completion of finally, then go to return 1;
public int test3 () {
int a = 0;
try {
a++;
return A;
} catch (Exception e) {
a++;
return A;
}finally{
a++;
}
}
There is also a return statement in the return,finally in 2.try.
The following code:--2, finally returns the result of return a under the finally statement.
public int test3 () {
int a = 0;
try {
a++;
return A;
} catch (Exception e) {
a++;
return A;
}finally{
a++;
return A;
}
}
3.return statement in the outermost case
The following code:--Returns 2,
public int test3 () {
int a = 0;
try {
a++;
} catch (Exception e) {
a++;
}finally{
a++;
}
return A;
}
4. Similar to the following:--return 1
public int test3 () {
int a = 0;
try {
a++;
return A;
} catch (Exception e) {
a++;
}finally{
a++;
}
return A;
}
To summarize: Finally, the result is returned with a return.
Only the return in the try (catch also with or outermost) will ignore the rest of the changes to the result, returning only the results returned in try.
Try: Catch.. Finally..