try { somethingDangerous(); } catch ( IOException e ) { out.println( "oh oh" ); throw new BadDataException(); } finally { file.close(); // always executed }