I am using Thread.setDefaultUncaughtExceptionHandler in the constructor of a Jdialog but it is not working. I also use it in the main of the JFrame and it works for events in the components of the JFrame, but since it doesn't work for events in the dialog I tried using it in the constructor of the dialog. However, that doesn't work; perhaps the code is executed in the thread of the JFrame.
A modal JDialog creates its own EventQueue to handle events that occur while it's open, and as a side effect bypasses the UncaughtExceptionHandler. The only way to deal with it is to use a hack involving a system property and an undocumented part of the EventDispatchThread API. First, you have to create a class to handle the exceptions; for example: You'll include the compiled class in your app (or a library, so long as it's available on the classpath), but you don't instantiate it. Then, either before or during your app's startup, set the system property "sun.awt.exception.handler" to the fully-qualified name of the class, for example: or And that's it! They were saying for years they were going to disable that hack, but just recently there's been talk of making it official instead.
Amazing, everything works fine if the dialog is non modal. My solution is to use non modal dialogs and make all the components of the calling frame or dialog disabled.
Post by:autobot
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
a bit of art, as a gift, the permaculture playing cards