<<< Checked exceptions example | Index | Unchecked exceptions >>> |
A reference of a superclass type can point to objects of its subclass
A program can determine if a reference variable points to a specific object type using the instanceof operator.
The catch blocks can be combined with the instanceof checks:
try { //... } catch ( Exception ex ) { if ( ex instanceof ArithmeticException ) { System.out.println( "Exception " + ex.toString() ); } else if ( ex instanceof InputMismatchException ) { System.out.println( "Exception " + ex.toString() ); } }
<<< Checked exceptions example | Index | Unchecked exceptions >>> |