You also can wrap the EventQueue like in this example: Catch exceptions in javax.swing application
If you want also log the exception, here I give you other option, maybe with more code, but it works properly.
import java.awt.AWTEvent;
import java.awt.EventQueue;
import javax.swing.JOptionPane;
import org.slf4j.Logger;
public class QueueEvenement extends EventQueue {
// CONSTRUCTOR
public QueueEvenement(Logger logger) {
super();
this.logger = logger;
}
protected void dispatchEvent(AWTEvent newEvent) {
try {
super.dispatchEvent(newEvent);
} catch (Throwable t) {
// Write log
logger.error(String.format("Erreur inconnue (%s - %s)",
t.getClass().getName(), t.getLocalizedMessage()));
}
}
}
After you code this class, you can install the wrap with the following line:
Toolkit.getDefaultToolkit().getSystemEventQueue().push(new EventQueueProxy());
This solution have the advantage of catch only the graphic, giving you more flexibility when you have to differentite between graphic exceptions (including the event handlers) and the other possible exceptions.
Regards!