<<< try/catch/finally rules, cont. | Index | Java Exception Hierarchy >>> |
The heading of a catch block specifies the type of exception it handles
A catch block can catch either
an exception of a specific type
an exception of a subclass of the specified superclass type
any exception, e.g. catch ( Exception ex )
Note: In a sequence of catch blocks, a catch block declaring an exception of a subclass type should be placed before any catch blocks declaring exceptions of a superclass type.
A catch block using the Exception catches all types of exceptions, because Exception is the superclass of all other exceptions. Therefore, it should be placed last in the sequence.
<<< try/catch/finally rules, cont. | Index | Java Exception Hierarchy >>> |