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

RFE: Awt ThreadGroup catches all UncaughtExceptions

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta
    • CPU:
      generic, sparc
    • OS:
      generic, solaris_2.5.1, solaris_10

      Description


      In certain circumstance you will want to use the uncaughtException method in
      the ThreadGroup class to deal with all uncaught exceptions

      However, the AWT event dispatch code appears to deal with all uncaught
      exceptions originating from the AWT event dispatch thread and thereby
      stops them from propogating upto the ThreadGroup uncaughtException method.

      The critical section of the awt is in src/java/awt/EventDispatchThread.java

            class EventDispatchThread extends Thread {
            ...
      try {

      ...process events off the AWT event queue inside a
      try/catch block...

      } catch (Throwable e) {
                        System.err.println(
                            "Exception occurred during event dispatching:");
                        e.printStackTrace();
                    }
        

      If you have a event handler method such as a listner any exeption raised
      in the users code which then generates an exception will be propergated
      to the EventDispatchThread exception handler and not the ThreadGroup
      handler.

      In most cases this is acceptable behaviour however where someone wants
      that bit more control and error recovery the awt routine gets in the way.


      For a real world example in the attachments called DemoApp.java which is
      a standalone application that creates a thread group and a thread creates
      a frame with a textarea and button.

      The Thread is run and then I've included a simple class to output the
      thread stack when the button is pressed. Here is an example of the
      output

      Thread Group: system Max Priority: 10
          Thread: Clock Priority: 12 Daemon
          Thread: Idle thread Priority: 0 Daemon
          Thread: Async Garbage Collector Priority: 1 Daemon
          Thread: Finalizer thread Priority: 1 Daemon
          Thread: AWT-Finalizer Priority: 9 Daemon
          Thread Group: main Max Priority: 10
              Thread: main Priority: 5
              Thread: Screen Updater Priority: 4
              Thread Group: DemoApp Main ThreadGroup Max Priority: 10
                  Thread: AWT-EventQueue-0 Priority: 5
                  Thread: AWT-Input Priority: 5
                  Thread: AWT-Motif Priority: 5

      Notice that the thread group "DemoApp Main ThreadGroup" is the parent of
      the AWT- threads so it would be possible to have exceptions propergate
      upwards.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ssisunw Ssi Ssi (Inactive)
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: