// Written by: Darren Gates & Ray Klefstad // Date: January 2000 // School: U.C. Irvine import java.awt.*; import java.applet.*; public class ExceptionsExample extends Applet { private TextArea myTextArea; private String message; public void init() { myTextArea = new TextArea(11, 35); add(myTextArea); message = ""; for (int i = 0; i < 10; i++) try { testException(i); } catch(MyException e) { message += e.toString() + "\n"; } myTextArea.setText(message); } public void testException(int value) throws MyException { if (value % 2 == 0) throw new MyException("even", value); } public static class MyException extends Exception { private int value; private String msg; public MyException(String msg, int value) { super(msg); this.value = value; this.msg = msg; } public String toString() { return value + " is " + msg; } } }