Java exception tracing

When I execute the code below, I see the output as:

Finally

Exception in thread "main" java.lang.NullPointerException on ClientTestConcepts.main (ClientTestConcepts.java:9)

Who prints bold statements.

public class ClientTestConcepts {
    public static void main(String []args){
        try{
            throw new NullPointerException();
        }
        finally{
            System.out.println("Finally");
        }
    }
}
+3
source share
2 answers

Java runtime.

It detects all exceptions that are not processed in the user code, and prints them on the error output (by default).

+7
source

, , . , , ThreadGroup.uncaughtException:

Java, - , Thread.UncaughtExceptionHandler.

uncaughtException ThreadGroup : (...)
    ... , , getName , , Throwable printStackTrace, .

, - .

+3

Source: https://habr.com/ru/post/1751016/


All Articles