Mega Code Archive

 
Categories / Java / Language Basics
 

Inheriting your own exceptions

// : c09:SimpleExceptionDemo.java // Inheriting your own exceptions. // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 // www.BruceEckel.com. See copyright notice in CopyRight.txt. class SimpleException extends Exception { } public class SimpleExceptionDemo {   public void f() throws SimpleException {     System.out.println("Throw SimpleException from f()");     throw new SimpleException();   }   public static void main(String[] args) {     SimpleExceptionDemo sed = new SimpleExceptionDemo();     try {       sed.f();     } catch (SimpleException e) {       System.err.println("Caught it!");     }   } } ///:~