The simplest version is to install a default exception handler:
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) {
But this catches the fuzzy exceptions thrown into other parts of the program.
However, you can use only runtime exceptions thrown from the swing event dispatch thread using a proxy (see this page for more information, the copied code is from there):
class EventQueueProxy extends EventQueue { protected void dispatchEvent(AWTEvent newEvent) { try { super.dispatchEvent(newEvent); } catch (Throwable t) {
Now install it like this:
Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventQueueProxy());
source share