FileDocCategorySizeDatePackage
ErrorHandlerTest.javaAPI DocExample1160Sun Apr 25 22:55:56 BST 2004None

ErrorHandlerTest

public class ErrorHandlerTest extends JFrame
Contrived program showing how to catch Exceptions that occur on the event dispatching thread. Define the System property "sun.awt.exception.handler" to name a class with a method
public void handle(Throwable t)
.

That really is all you have to do to catch GUI Exceptions. But it may change at any time (hence the name sun.awt...).

author
Ian Darwin.

Fields Summary
Constructors Summary
ErrorHandlerTest()
A fairly banal GUI, just to show interaction.

		super("GUI");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container cp = getContentPane();
		JButton bx = new JButton("Throw!");
		bx.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				throw new IllegalArgumentException("foo");
			}
		});
		cp.add(bx);
		setBounds(200, 200, 200, 100);
	
Methods Summary
public static voidmain(java.lang.String[] args)

		// Tell AWT to invoke my Handler.
		System.setProperty("sun.awt.exception.handler", "ErrorHandler");

		// Now create and show the GUI.
		new ErrorHandlerTest().setVisible(true);