// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
public class TryResCus17 {
    public static void main(String[] args) throws Exception {
        try (MyRes r = new MyRes(false)) {
            r.test();
        }
        try (MyRes r = new MyRes(true)) {
            r.test();
        }
    }
}

class MyRes implements AutoCloseable {
    private boolean willthrow;
    public MyRes(boolean willthrow) {
        this.willthrow = willthrow;
        System.out.println("constuctor called");
    }
    public void test() throws Exception {
        if(willthrow) {
            throw new Exception("Ooops");
        }
    }
    public void close() {
        System.out.println("close called");
    }
}
