Top


定義場所(file name)

jdk/src/share/classes/java/lang/ThreadGroup.java

説明(description)

    /**
     * Called by the Java Virtual Machine when a thread in this
     * thread group stops because of an uncaught exception, and the thread
     * does not have a specific {@link Thread.UncaughtExceptionHandler}
     * installed.
     * <p>
     * The <code>uncaughtException</code> method of
     * <code>ThreadGroup</code> does the following:
     * <ul>
     * <li>If this thread group has a parent thread group, the
     *     <code>uncaughtException</code> method of that parent is called
     *     with the same two arguments.
     * <li>Otherwise, this method checks to see if there is a
     *     {@linkplain Thread#getDefaultUncaughtExceptionHandler default
     *     uncaught exception handler} installed, and if so, its
     *     <code>uncaughtException</code> method is called with the same
     *     two arguments.
     * <li>Otherwise, this method determines if the <code>Throwable</code>
     *     argument is an instance of {@link ThreadDeath}. If so, nothing
     *     special is done. Otherwise, a message containing the
     *     thread's name, as returned from the thread's {@link
     *     Thread#getName getName} method, and a stack backtrace,
     *     using the <code>Throwable</code>'s {@link
     *     Throwable#printStackTrace printStackTrace} method, is
     *     printed to the {@linkplain System#err standard error stream}.
     * </ul>
     * <p>
     * Applications can override this method in subclasses of
     * <code>ThreadGroup</code> to provide alternative handling of
     * uncaught exceptions.
     *
     * @param   t   the thread that is about to exit.
     * @param   e   the uncaught exception.
     * @since   JDK1.0
     */

名前(function name)

    public void uncaughtException(Thread t, Throwable e) {

本体部(body)

  {- -------------------------------------------
  (1) 以下のように処理を行う.

      * 親の ThreadGroup がいる場合 (= parent フィールドが null ではない場合): 

        そちらに委譲する.

      * 親の ThreadGroup はいないが, デフォルトの UncaughtExceptionHandler がセットされている場合
        (= Thread.getDefaultUncaughtExceptionHandler() が null ではない場合):

        Thread.getDefaultUncaughtExceptionHandler() で
        デフォルトの UncaughtExceptionHandler を取得し, それを呼び出す.

      * 親の ThreadGroup がおらず, デフォルトの UncaughtExceptionHandler もセットされていない場合: 

        この場で適当な出力("Exception in thread ...") と printStackTrace() を出して終了.
      ---------------------------------------- -}

            if (parent != null) {
                parent.uncaughtException(t, e);
            } else {
                Thread.UncaughtExceptionHandler ueh =
                    Thread.getDefaultUncaughtExceptionHandler();
                if (ueh != null) {
                    ueh.uncaughtException(t, e);
                } else if (!(e instanceof ThreadDeath)) {
                    System.err.print("Exception in thread \""
                                     + t.getName() + "\" ");
                    e.printStackTrace(System.err);
                }
            }
        }

This document is available under the GNU GENERAL PUBLIC LICENSE Version 2.