src/share/classes/java/lang/Thread.java

Print this page


   1 /*
   2  * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1834      * terminates due to an uncaught exception.
1835      * <p>When a thread is about to terminate due to an uncaught exception
1836      * the Java Virtual Machine will query the thread for its
1837      * <tt>UncaughtExceptionHandler</tt> using
1838      * {@link #getUncaughtExceptionHandler} and will invoke the handler's
1839      * <tt>uncaughtException</tt> method, passing the thread and the
1840      * exception as arguments.
1841      * If a thread has not had its <tt>UncaughtExceptionHandler</tt>
1842      * explicitly set, then its <tt>ThreadGroup</tt> object acts as its
1843      * <tt>UncaughtExceptionHandler</tt>. If the <tt>ThreadGroup</tt> object
1844      * has no
1845      * special requirements for dealing with the exception, it can forward
1846      * the invocation to the {@linkplain #getDefaultUncaughtExceptionHandler
1847      * default uncaught exception handler}.
1848      *
1849      * @see #setDefaultUncaughtExceptionHandler
1850      * @see #setUncaughtExceptionHandler
1851      * @see ThreadGroup#uncaughtException
1852      * @since 1.5
1853      */

1854     public interface UncaughtExceptionHandler {
1855         /**
1856          * Method invoked when the given thread terminates due to the
1857          * given uncaught exception.
1858          * <p>Any exception thrown by this method will be ignored by the
1859          * Java Virtual Machine.
1860          * @param t the thread
1861          * @param e the exception
1862          */
1863         void uncaughtException(Thread t, Throwable e);
1864     }
1865 
1866     // null unless explicitly set
1867     private volatile UncaughtExceptionHandler uncaughtExceptionHandler;
1868 
1869     // null unless explicitly set
1870     private static volatile UncaughtExceptionHandler defaultUncaughtExceptionHandler;
1871 
1872     /**
1873      * Set the default handler invoked when a thread abruptly terminates


   1 /*
   2  * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1834      * terminates due to an uncaught exception.
1835      * <p>When a thread is about to terminate due to an uncaught exception
1836      * the Java Virtual Machine will query the thread for its
1837      * <tt>UncaughtExceptionHandler</tt> using
1838      * {@link #getUncaughtExceptionHandler} and will invoke the handler's
1839      * <tt>uncaughtException</tt> method, passing the thread and the
1840      * exception as arguments.
1841      * If a thread has not had its <tt>UncaughtExceptionHandler</tt>
1842      * explicitly set, then its <tt>ThreadGroup</tt> object acts as its
1843      * <tt>UncaughtExceptionHandler</tt>. If the <tt>ThreadGroup</tt> object
1844      * has no
1845      * special requirements for dealing with the exception, it can forward
1846      * the invocation to the {@linkplain #getDefaultUncaughtExceptionHandler
1847      * default uncaught exception handler}.
1848      *
1849      * @see #setDefaultUncaughtExceptionHandler
1850      * @see #setUncaughtExceptionHandler
1851      * @see ThreadGroup#uncaughtException
1852      * @since 1.5
1853      */
1854     @FunctionalInterface
1855     public interface UncaughtExceptionHandler {
1856         /**
1857          * Method invoked when the given thread terminates due to the
1858          * given uncaught exception.
1859          * <p>Any exception thrown by this method will be ignored by the
1860          * Java Virtual Machine.
1861          * @param t the thread
1862          * @param e the exception
1863          */
1864         void uncaughtException(Thread t, Throwable e);
1865     }
1866 
1867     // null unless explicitly set
1868     private volatile UncaughtExceptionHandler uncaughtExceptionHandler;
1869 
1870     // null unless explicitly set
1871     private static volatile UncaughtExceptionHandler defaultUncaughtExceptionHandler;
1872 
1873     /**
1874      * Set the default handler invoked when a thread abruptly terminates