When you've got uncaught exceptions that terminate your application
you've got a bug. And a bug has to be fixed. Things change a little bit
when you have to maintain a five year old application and the
developers reveal more bugs than the tester. Especially when the bugs
terminate the application without a notice. Then you would like to have
a second line of defense that warns the user that something nasty has
happened.
Searching for uncaught exceptions took me quickly to the blog post http://stuffthathappens.com/blog/2007/10/07/programmers-notebook-uncaught-exception-handlers/.
There
Eric
Burke
introduces the UncaughtExceptionHandler.
This
sounded like a cool solution until I've read the warning that it
won't work with modal dialogs. Well the application in question is a
Swing Rich-Client that uses modal dialogs.
While I was going through the stack trace of a sample application I've
found that all AWTEvents go through the EventQueue class and I knew
that you can provide you own EventQueue to swing. So I've made a simple
test application and it worked. This seemed far to easy. So I've
searched the web and found that someone else had the same solution. http://ruben42.wordpress.com/2009/03/30/catching-all-runtime-exceptions-in-swing/
describes this solution far more extensive as I would like to do. So go
over there and read it.
There
is an update for this blog entry.