Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RuntimeExceptions in event thread  RSS feed

 
Kevin Stembridge
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Does anyone know what happens behind the scenes in the event-dispatching thread when a RuntimeException occurs?

For example, when a RuntimeException is being thrown from within an actionPerformed method, the GUI shows no effect but the stack trace is printed to System.err. Is there anyway that I can intercept all runtime exceptions on the event thread without having to put catch clauses in all my event listener methods?

Cheers,
Kevin
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Originally posted by Kevin Stembridge:
For example, when a RuntimeException is being thrown from within an actionPerformed method, the GUI shows no effect but the stack trace is printed to System.err.


I would expect that your application will have 'frozen' or can't repaint itself anymore when this happens. If your AWT thread dies, then it's bad news for your application. When this happens, minimize that application and then maximize and the frame will probably be grey.

Originally posted by Kevin Stembridge:
Is there anyway that I can intercept all runtime exceptions on the event thread without having to put catch clauses in all my event listener methods?


You could create a runnable that encapsulates the tasks to be done in the event listener methods. Then depending on the task, you can execute it with a call to SwingUtilites.invokeLater(), SwingUtilities.invokeAndWait() or just make a plain old thread out of it and call the start() method.

If you do this, then if one of these tasks throws a runtime error, it won't kill the AWT thread.

I don't think it's possible to intercept the exceptions without using catch clauses everywhere though.

I would be interested to hear of other alternatives.

Cheers, Jared.
[ June 13, 2005: Message edited by: Jared Cope ]
 
Scott Delap
author
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin,

JavaLobby recently had a discussion about ways to handle this. There are a couple suggestions including creating your own thread group.

http://www.javalobby.org/java/forums/t19003.html

I did some checking into your question about what the EDT does on a runtime exception. If you look at the EventDispatchThread class, you will notice that a new EDT is started if the current one dies.

Scott Delap
ClientJava.com
Desktop Java Live
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!