Given below is my example about a simple finally block.
public class Ex2 {
public static void main(String args[]) throws ArithmeticException {
System.out.println(Ex2.myTestingFuncn());
}
public static int myTestingFuncn() {
try {
// first execution
return 5;
} finally {
// second execution
System.out.println("finally");
}
}
}
This results are
finally
5
as expected.
But when this happened finally block overrides try block's value.
try {
// first execution
return 5;
} finally {
// second execution
return 12;
}
Result : 12
How does this happens? I mean what is the order of these blocks execution?
Please help.
Thank you