Java exception tracking stack definition and usage example

This article describes the definition and usage of Java exception tracking stack. Share with you for your reference, as follows:

1、 Introduction to exception tracking stack

The printstacktrace method of the exception object is used to print the tracking stack information of the exception. According to the output result of the printstacktrace method, we can find the source of the exception and track the process of triggering the exception all the way.

2、 Application of exception tracking stack in main method

1 code example

2 operation results

3 Result Analysis

As long as the exception is not completely captured, the exception gradually propagates outward from the method where the exception occurs, first to the caller of the method, and the caller of the method creates it again... Until finally to the main method. If the main method still does not handle the exception, the JVM will abort the program and print the exception tracking stack information.

3、 Application of exception tracking stack in multithreading

1 code example

2 operation results

3 Result Analysis

The program has an arithmetexception exception in the run method of thread. The source of this exception is the secondmethod method of threadexception, which is located in line 16 of the file. The exception is propagated to the run method of the thread class and ends.

For more Java related content, interested readers can view the special topics of this site: introduction and advanced tutorial of java object-oriented programming, tutorial of Java data structure and algorithm, summary of Java DOM node operation skills, summary of java file and directory operation skills, and summary of Java cache operation skills

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>