As you have seen in the listing, there are two exit points the return statement on Line 14 and the – return statement on Line 18. Listing 3.18 the test class, TestFinallyBlock. When Line 7 is executed, the method test calls the method display in the class FinallyBblock, and both lines of codes are executed without any exception being thrown. Hence, the catch block is not executed. That being the case, one would have thought that the return statement on Line 14 would have been executed; instead the finally block is executed first.
As you have seen in the listing, there are two exit points – the return statement on Line 14 and the return statement on Line 18. Listing 3.18 the test class, TestFinallyBlock. When Line 7 is executed, the method test calls the method display in the class FinallyBblock, and both lines of codes are executed without any exception being thrown. Hence, the catch block is not executed. That being the case, one would have thought that the return statement on Line 14 would have been executed; instead the finally block is executed first.
chapter.3.1.docx