class FileException inherits Exception { ... }; class BadFormatException inherits FileException { ... }; class IOException inherits Exception { ... }; // main code... // try { readDataFromFile( "file.dat" ); } catch ( FileException e ) { System.out.println("Something went wrong"); } int readDataFromFile( String filename ) throws FileException { // ... fileRef = openFile( filename ); while ( data = readLine( fileRef ) ) { ... } } File openFile( String filename ) throws IOException { ... } String readLine( File file ) throws BadFormatException { ... }