FileDocCategorySizeDatePackage
ThreadBasedCatcher.javaAPI DocExample1099Sat Mar 20 14:43:28 GMT 2004None

ThreadBasedCatcher

public class ThreadBasedCatcher extends JFrame
ThreadBasedCatcher - Demonstrate catching uncaught exceptions thrown in an unrelated Thread.
author
ian
verion
$Id: ThreadBasedCatcher.java,v 1.2 2004/03/20 20:43:27 ian Exp $

Fields Summary
Constructors Summary
public ThreadBasedCatcher()

		Container cp = getContentPane();
		JButton crasher = new JButton("Crash");
		cp.add(crasher);
		crasher.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				throw new RuntimeException("You asked for it");
			}
		});
		Thread.setDefaultUncaughtExceptionHandler(
				new Thread.UncaughtExceptionHandler(){
					public void uncaughtException(Thread t, Throwable ex){
						System.out.println(
							"You crashed thread " + t.getName());
						System.out.println(
							"Exception was: " + ex.toString());
					}
				});
		pack();
	
Methods Summary
public static voidmain(java.lang.String[] args)

		new ThreadBasedCatcher().setVisible(true);