public class TryWithResources {

	public static void main(String[] args) throws Exception {

		try ( OpenDoor door = new OpenDoor() ) {
			door.swing(); /*this throws a SwingExecption*/
		}
		catch (Exception e) { 
			System.out.println("Is there a draft? " + e.getClass());
		}
		finally {
			System.out.println("I'm putting a sweater on, regardless. ");
		}
	}
}

class OpenException extends Exception {}
class SwingException extends Exception {}
class CloseException extends Exception {}

/*
class OpenDoor implements AutoCloseable {

	public OpenDoor() throws Exception {
		System.out.println("The door is open.");
	}
	public void swing() throws Exception {
		System.out.println("The door is becoming unhinged.");
		throw new SwingException();
	}

	public void close() throws Exception {
		System.out.println("The door is closed.");
    }
}
*/

class OpenDoor implements AutoCloseable {

	public OpenDoor() throws Exception {
		System.out.println("The door is open.");
	}
	public void swing() throws Exception {
		System.out.println("The door is becoming unhinged.");
		throw new SwingException();
	}

	public void close() throws Exception {
		System.out.println("The door is closed.");
		throw new CloseException(); // throwing CloseException 
	}
}

/*
 * From: 
 * https://www.theserverside.com/tutorial/OCPJP-OCAJP-Java-7-Suppressed-Exceptions-Try-With-Resources
/*
 * */
