//: WithFinally.java // Finally Guarantees cleanup class Switch2 { boolean state = false; boolean read() { return state; } void on() { state = true; } void off() { state = false; } } public class WithFinally { static Switch2 sw = new Switch2(); public static void main(String[] args) { try { sw.on(); // Code that can throw exceptions... sw.off(); } catch ( NullPointerException e) { System.out.println("NullPointerException"); sw.off(); } catch ( IllegalArgumentException e) { System.out.println("IOException"); sw.off(); } finally { sw.off(); } } }