/** * Dispatch an uncaught exception to the handler. This method is * intended to be called only by the JVM. */privatevoiddispatchUncaughtException(Throwablee){getUncaughtExceptionHandler().uncaughtException(this,e);}
/** * Returns the handler invoked when this thread abruptly terminates * due to an uncaught exception. If this thread has not had an * uncaught exception handler explicitly set then this thread's * <tt>ThreadGroup</tt> object is returned, unless this thread * has terminated, in which case <tt>null</tt> is returned. * @since 1.5 * @return the uncaught exception handler for this thread */publicUncaughtExceptionHandlergetUncaughtExceptionHandler(){returnuncaughtExceptionHandler!=null?uncaughtExceptionHandler:group;}
/** * 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 */publicvoiduncaughtException(Threadt,Throwablee){if(parent!=null){parent.uncaughtException(t,e);}else{Thread.UncaughtExceptionHandlerueh=Thread.getDefaultUncaughtExceptionHandler();if(ueh!=null){ueh.uncaughtException(t,e);}elseif(!(einstanceofThreadDeath)){System.err.print("Exception in thread \""+t.getName()+"\" ");e.printStackTrace(System.err);}}}