JDK-6791501 : Official API for Swing EDT Exception Handler
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-01-08
  • Updated: 2011-01-19
  • Resolved: 2009-01-11
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE REQUEST :
There shall be an API that is port of the official Swing specification, which allows the set a handler for alle exceptions thrown inside of the EDT, especially runtime exceptions in event handlers and property listeners.

JUSTIFICATION :
Currently (6u10) there are two ways to handle these exceptions in a global way, but both do not work:

(a) Thread.currentThread().setUncaughtExceptionHandler -- this just is doing nothing for the EDT. I tried it out with 6u10 by throwing a RuntimeException in a property change. It has just no effect at all.

(b) sun.awt.exception.handler -- this is not part of the Swing API and propably will not work on other vendor's JREs; also it might be gone in future.

Since it is a common problem "How to handle an exception that was thrown in the EDT?" after years of lengthy discussions and half-baked workarounds, there should be a definitive, single, official way to deal with that problem.

See these discussions:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6727884
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4714232

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
There shall be one single, official way that works exactly the same in all versions of all JREs of all vendors.
ACTUAL -
(a) Does not work in 6uN

(b) Possibly does not work in other vendors' JREs.

---------- BEGIN SOURCE ----------
        EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                    public void uncaughtException(Thread t, Throwable e) {
                        System.err.println("*****");
                    }
                });
            }
        });


            this.yearSpinner.addPropertyChangeListener("year", new PropertyChangeListener() {
                public final void propertyChange(final PropertyChangeEvent event) {
                    throw new RuntimeException("FOO BAR !");
                }
            });

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
There is no workaround that will work on all JREs of all vendors.