Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <strong>EDT</strong> class (<code>java.awt.EventDispatchThread</code>, don't look for it in the javadoc, this class is <em>package private</em>) has changed a lot since the origins of AWT.</p> <p>In <strong>JDK6</strong>, you can see that this class now can properly handle exceptions occuring inside the EDT. Exception handling is a bit complex in the current version:</p> <ul> <li>if you have set the <code>sun.awt.exception.handler</code> property, then your handler will be called for every exception thrown by developer's code called inside the EDT (compatibility with previous JDK versions is ensured).</li> <li>otherwise, any exception will be <strong>rethrown</strong>, hence will stop the current EDT, and any default <code>UncaughtExceptionHandler</code> will be able to catch it, as your snippet demonstrates.</li> </ul> <p><strong>BUT</strong> (and this is <strong>very important</strong>), if you carefully look at the code of EDT, you'll see that this mechanism won't work if the exception occurs in the EDT <strong>while a modal dialog is displayed</strong> (I guess this is because EDT and <code>EventQueue</code> management is quite complicated and I would even dare say "<em>messy</em>": a lot of code looks like hacks in there).</p> <p>In this exact situation, exceptions will be logged to <code>System.err</code>, except if you have set the <code>sun.awt.exception.handler</code> property. Having a default <code>UncaughtExceptionHandler</code> will not help.</p> <p>So my take on this is that, YES, <strong>you should still bother with <code>sun.awt.exception.handler</code> property</strong>, except if you can say for sure that your application doesn't use modal dialogs (don't forget that <code>JOptionPane</code> dialogs are also modal).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload