• Post Reply Bookmark Topic Watch Topic
  • New Topic

Default Uncaught Exception Handler fails in JDialog

 
Alejandro Barrero
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks in advance for your help.

Alejandro Barrero
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alejandro Barrero
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!