Home Segments Top Top Previous Next

610: Mainline

Note that exceptions form a class hierarchy. The exception actually thrown when a file does not exist is an instance of the FileNotFoundException class.

Because the IOException class is a superclass of the FileNotFoundException class, the FileNotFoundException instance is also an instance of the IOException class, enabling the catch block with the IOException parameter to catch FileNotFoundException instances.

A catch block with an Exception parameter will catch instances of any exception.

*-----------------------* 
| Exception             | 
*-----------------------* 
         ^     
         | extends 
*-----------------------* 
| IOException           | 
*-----------------------* 
         ^    ^ 
         |    | extends 
         |    *------------------------* 
         |                             | 
         | extends                     | 
*-----------------------*  *---------------- 
| FileNotFoundException |  |                     
*-----------------------*  *-------------