class CoffeePot { } // class CoffeePot class NoCoffeePotException extends Exception { } // class NoCoffeePotException public class Dinner { CoffeePot coffeePot; private void eatAppetizer() { // Ät förrätten } private void eatMainCourse() { // Ät huvudrätten } private void eatDessert() { // Ät efterrätten } private void drinkCoffee() throws NoCoffeePotException { if (coffeePot == null) throw new NoCoffeePotException(); else { // Drick kaffe } } private void eatDinner() throws NoCoffeePotException { eatAppetizer(); eatMainCourse(); eatDessert(); drinkCoffee(); } public static void main(String[] args) { Dinner d = new Dinner(); try { d.eatDinner(); } catch (NoCoffeePotException e) { System.out.println("Ingen kaffepanna!"); } catch (Exception e) { System.out.println("Något annat gick snett."); } } // main } // class Dinner