Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4158296

need pluggable handler for unchecked exceptions on EventDispatchThread

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.1, 1.1.6
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic, solaris_10

      Description

       Date: Thu, 16 Jul 1998 10:25:02 -0400
      MIME-Version: 1.0
      To: David Soroko <###@###.###>
      CC: Ben Hutchison <###@###.###>, "###@###.###" <###@###.###>, ###@###.###
      Subject: Re: Catching exceptions in AWT/Swing originated threads
      Content-Transfer-Encoding: 7bit

      David Soroko wrote:

      > The problem is in the EventDispatchThread class. Unbelievable as it is
      > all unhandled exceptions originating from GUI are handled in the following
      > way (jdk 1.1.6):
      > ............................
      > } catch (Throwable e) {
      > System.err.println(
      > "Exception occurred during event dispatching:");
      > e.printStackTrace();
      > }
      > .......................

      Horrendous isn't it.

      This makes it a herculean task to handle unchecked exceptions (RuntimeExceptions and Errors) in a safe consistent way for an entire system. I can't count all the times I've had to override processEvent to catch things just before
      this code occurs. "Luckily" we've already had to subclass almost every AWT widget class for one reason or another :-(

      Count your blessings though. The 1.1_Final only caught Exceptions not Throwables. Errors took out the entire event thread.

      I was hoping that this behavior would be fixed in newer releases to allow a "pluggable" handler. Something like:

           // new public method in EventDispatchThread or Toolkit
           addUncaughtThrowableHandler(ThrowableHandler h);

           public Interface ThrowableHandler {
               public static final int RESUME;
               public static final int RETRY;
               public static final int EXIT;

               /**
                * called when an unhandled Throwable occurs
                * @return one of the above constants.
                * Of course this is only a suggestion to the caller.
                **/

               int handleThrowable(Throwable t);
           }


      handleThrowable could be a void method for that matter. The key is that you get notified about uncaught exceptions and can then deal with them in an appropriate manner.

      Yes, I know you can handle this by creating your own ThreadGroup but you don't always have that option.

      1.2b3 code looks just the same as the 1.1.6. Guess I should have spoken up sooner...
      --
      Ralph M. Prescott Systems Consultant
      ###@###.### Custom Development Services Division
      ###@###.### LPA Software Inc.



      Name: krT82822 Date: 05/01/99


      Class java.awt.EventDispatchThread, in its run method,
      catches Throwable, and prints it to stderr. As a result,
      the caller application or applet never gets a chance to
      catch the exception and sees output sent to stderr without
      its consent.

      Heres' the code of java.awt.EventDispatchThread:

          public void run() {
             while (doDispatch && !isInterrupted()) {
                  try {
                      AWTEvent event = theQueue.getNextEvent();
                      theQueue.dispatchEvent(event);
                  } catch (ThreadDeath death) {
                      return;

      } catch (InterruptedException interruptedException) {
      return; // AppContext.dispose() interrupts all
      // Threads in the AppContext

      -------> } catch (Throwable e) {
                      System.err.println(
                          "Exception occurred during event dispatching:");
                      e.printStackTrace();
                  }
              }
          }
      (Review ID: 57608)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              duke J. Duke (Inactive)
              Reporter:
              amfowler Anne Fowler (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: