Forums Register Login

Default Uncaught Exception Handler fails in JDialog

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
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
https://gardener-gift.com


reply
reply
This thread has been viewed 3087 times.
Similar Threads
urgent please help
JDialog in front when JFrame on top?
What if the FileDialog is invoked from a JDialog???
SwingWorker and Modal JDialogs
fix JDialog position relative to its parent JFrame component
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:06:50.