concept catch block in category java

This is an excerpt from Manning's book Java SE 11 Programmer I Certification Guide.
Exam tip A method can declare to throw any type of exception, checked or unchecked, even if it doesn’t do so. But a try block can’t define a catch block for a checked exception (other than Exception) if the try block doesn’t throw that checked exception or use a method that declares to throw that checked exception.
Figure 12.16 A visual way to remember that the order matters for exceptions caught in the catch blocks
![]()

This is an excerpt from Manning's book OCA Java SE 8 Programmer I Certification Guide.
Purpose: A finally block can’t be placed before the catch blocks. A number of programmers have compared this question with placing the label default before the label case in a switch construct. Though the latter approach works, the finally and catch blocks aren’t so flexible.
A method can declare to throw any type of exception, checked or unchecked, even if it doesn’t do so. But a try block can’t define a catch block for a checked exception (other than Exception) if the try block doesn’t throw that checked exception or use a method that declares to throw that checked exception.
It’s interesting to note that a finally block will execute even if the code in the try block or any of the catch blocks defines a return statement. Examine the code in figure 7.14 and its output, and note when the class ReturnFromCatchBlock is unable to open file.txt.
Figure 7.14. The finally block executes even if an exception handler defines a return statement.
![]()
As you can see from figure 7.14’s code output, the flow of control doesn’t return to the method main when the return statement executes in the catch handler of FileNotFoundException. It continues with the execution of the finally block before control is transferred back to the main method. Note that control isn’t transferred to the println statement "Next task.. " that follows the try block because the return statement is encountered in the catch block, as mentioned previously.