Shouldn't an exception be thrown in the catch block and returned?
It is captured, and this return statement is executed ... but then the return value is effectively replaced by the return statement in the finally block, which will execute if there was an exception.
For more information on features, see JLS 14.20.2 . In your case, this is the way:
If the execution of the try block ends abruptly due to a throw of the value of V, then there is a choice:
If the run-time type V is an assignment compatible with the perceptible exception class of any catch clause from the try statement, then the first (leftmost) catch clause is selected. The value V is assigned to the parameter of the selected catch clause, and a block of this catch condition is executed. Then there is a choice:
If the catch lock completes normally [... is ignored because it is not)
If the catch block terminates abruptly for reason R, then the finally block is executed. Then there is a choice:
If the finally block completes normally [... is ignored because it does not work]
If the finally block completes abruptly for mind S, then the try statement terminates abruptly for reason S (and reason R is discarded).
So, the main line is important - the โreason Sโ (in our case, returning the value 11) ends with the try ending abruptly.
source share