java exception trace
When i execute the belo开发者_Python百科w code,I am seeing the output as:
Finally
Exception in thread "main" java.lang.NullPointerException at ClientTestConcepts.main(ClientTestConcepts.java:9)
Who prints the bold faced statements.
public class ClientTestConcepts {
public static void main(String []args){
try{
throw new NullPointerException();
}
finally{
System.out.println("Finally");
}
}
}
The Java runtime.
It catches all exceptions not handled in user code, and prints them on the error output (by default).
Each thread has a default uncaught exception handler that runs when an exception makes it to the top of the stack. The one you are observing is provided by ThreadGroup.uncaughtException:
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 Thread.UncaughtExceptionHandler installed.
The uncaughtException method of ThreadGroup does the following: (...)
... a message containing the thread's name, as returned from the thread's getName method, and a stack backtrace, using the Throwable's printStackTrace method, is printed to the standard error stream.
If you want some other behaviour register an uncaught exception handler for the thread.
精彩评论