public class ExceptionDemo{ public static void main(String[] args) throws DemoException{ ExceptionDemo object = new ExceptionDemo(); System.out.println("metoden main"); object.p(); } public void p() throws DemoException{ System.out.println("metoden p"); try{ q(true); } catch (DemoException e){ System.out.println(e); System.out.println("Reparation i p"); q(false); // false means better version } } public void q(boolean b) throws DemoException{ System.out.println("metoden q"); r(b); } public void r(boolean b) throws DemoException{ System.out.println("metoden r"); s(b); } public void s(boolean b) throws DemoException{ System.out.println("metoden s"); if (b) throw (new DemoException("Vi har et problem")); else System.out.println("Nu går det bedre i s"); } } class DemoException extends Exception{ public DemoException(String problem){ super(problem); } }