//: c10:ExceptionMethods.java // From 'Thinking in Java, 2nd ed.' by Bruce Eckel // www.BruceEckel.com. See copyright notice in CopyRight.txt. // Demonstrating the Exception Methods. // // import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.util.*; import com.bruceeckel.swing.*; import com.bruceeckel.util.*; public class ExceptionMethods extends JApplet { JTextArea Xout = new JTextArea(10, 50); public void init() { Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(new JLabel("ExceptionMethods!")); cp.add(new JScrollPane(Xout)); try { throw new Exception("Here's my Exception"); } catch(Exception e) { Xout.append("Caught Exception\n"); Xout.append( "e.getMessage(): " + e.getMessage() + "\n"); Xout.append( "e.getLocalizedMessage(): " + e.getLocalizedMessage() + "\n"); Xout.append("e.toString(): " + e + "\n"); Xout.append("e.printStackTrace():\n"); e.printStackTrace(System.err); } } public static void main(String[] args) { Console.run(new ExceptionMethods(), 600, 300); } } ///:~