On Page 238 of Sierra and Bates, they say
A finally block encloses code that is always executed at some point after the try block, whether an exception was thrown or not. Even if there is a return statement in the try block, the finally block executes right after the return statement! (Boldened by G. Chao)
And the following code is from Question 15 of Marcus Green at
http://www.jchq.net/mockexams/exam1.htm , (Line number added by G. Chao)
If the file "Hello.txt" does not exist, we get this output:
No such file found, doing finally, -1
If we comment out Line 13, the output will be:
No such file found, doing finally, 0
Both cases show that the finally block executes
before the return statement, not after it.
If we comment out both return statements and put a return statement right in the try block like so:
then the code won't compile at all, the compiler would say that we are missing a return statement.
So, are Sierra and Bates wrong?