catch exceptions in EventDispatchThread

B

bernd_no_junk

Hi, I would like to catch all exception thrown
by the EventDispatchThread.
How do I do this?

Greetings

Bernd
 
A

Alan Moore

Hi, I would like to catch all exception thrown
by the EventDispatchThread.
How do I do this?

This approach uses an undocumented feature of EventDispatchThread.
Actually, it is described in the doc for the handleException() method,
but you have to go to the source code to read it. The doc also says
this feature will be removed in a future release (but it's still there
in Tiger).


public class MyApp
{
public static void main(String[] args)
{
System.setProperty("sun.awt.exception.handler",
"MyApp$EDTErrorHandler");

// etc.
}

/**
* This class will be instantiated the first time an
* exception is thrown on the EDT.
*/
public static class EDTErrorHandler
{
/**
* This method is invoked by the AWT event dispatch
* mechanism when an unexpected exception or error
* is thrown during event dispatching.
*/
public void handle(Throwable t)
{
// handle the exception
}
}
}
 
C

Chris Smith

Hi, I would like to catch all exception thrown
by the EventDispatchThread.
How do I do this?

There are a number of approaches. Here's one:

Toolkit.getDefaultToolkit().getSystemEventQueue()
.push(new EventQueue() {
protected void dispatchEvent(AWTEvent event)
{
try
{
super.dispatchEvent(event);
}
catch (Exception e)
{
handleException(e);
}
}
});


--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top