import java.net.URL; import java.net.MalformedURLException; import java.lang.ArithmeticException; public class testExcp { static public void main(String args[]) { myClass data = new myClass(); try { data.mymethod(); // it throws Err1 and Err2 } catch (Err1 e) { System.out.println("Got Err1 " + e.getMessage()); } catch (Err2 e) { System.out.println("Got Err2 " + e.getMessage()); } ... } } class myClass { int x, y, z; void mymethod() throws Err1, Err2 { x = 0; // ridiculous, we're forcing the exceptions y = 1; // to be thrown if (x == 3) throw new Err1("x is " + x); if (y == 1) throw new Err2("y is " + y); try { z = y / x; } catch (ArithmeticException e) { System.out.println("Got ArithmeticException: " + e.getMessage()); return; } try { URL myURL = new URL("http://www.phoenixtech.com"); } catch (MalformedURLException e) { System.err.println("Got MalformedURLException: " + e.getMessage()); return; } ... } } class Err1 extends RuntimeException { Err1(String s) { super(s); } } class Err2 extends RuntimeException { Err2(String s) { super(s); } }