報價JLS 11:
30/X - 違反了Java語言的語義約束 - 因此會出現異常。
If no catch clause that can handle an exception can be found,
then the **current thread** (the thread that encountered the exception) is terminated
終止前 - 未捕獲的異常是按以下規則處理:
(1) If the current thread has an uncaught exception handler set,
then that handler is executed.
(2) Otherwise, the method uncaughtException is invoked for the ThreadGroup
that is the parent of the current thread.
If the ThreadGroup and its parent ThreadGroups do not override uncaughtException,
then the default handler's **uncaughtException** method is invoked.
你的情況:
它進入Thread類異常後
/**
* Dispatch an uncaught exception to the handler. This method is
* intended to be called only by the JVM.
*/
private void dispatchUncaughtException(Throwable e) {
getUncaughtExceptionHandler().uncaughtException(this, e);
}
然後按照規則2進入ThreadGroup uncaugthException - 由於沒有exceptionHandler是d efined它去否則,如果 - 和線程終止
public void uncaughtException(Thread t, Throwable e) {
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);
}**
}
}
http://www.javamex.com/tutorials/exceptions/exceptions_uncaught_handler.shtml – Tom
如果你沒有try/catch語句的例外,那麼, JVM捕獲它。 – OldProgrammer