Why the return in try doesn't terminate the method?
Is it bad practice to return from within a try catch finally block?
You have to be aware that when you put a return inside a try-catch statement, the return itself is held and managed by the exeption handling block.
The exception block only STORES your return and it really returns it ONLY after all the verifications are done, which doesn't mean that the finally block will really have an impact on your return:
public int returnVal() {
int i = 0;
try {
return i;
}
finally {
i = 99;
}
}
In this case, the return will still be 0.
But in the case you mentioned in your question, you affect the return a second time, and as the exception block dosen't want to let your return go until it's done with ALL its verification, you're just always storing a return value 2 times in your exception block. The result will always be 3.
Just keep in mind that if you put a return inside a try-catch-finally, that return will not return until the finaly block has run; the return itself is just being stored until everything has been verified.