Java anomaly analysis; Printstacktrace and Fillinstacktrace

Source: Internet
Author: User
Tags stack trace throwable
stack Traces of Java exceptions (stack trace)

When an exception is caught, some processing is often required. The simpler and more straightforward way is to print the exception stack trace. Talking about the stack trajectory, probably a lot of people like me, the first reaction is the Printstacktrace () method. In fact, in addition to this method, there are some other content is related to the stack trajectory.

1.printStackTrace ()

First, it needs to be clear that this method does not come from the exception class. In addition to defining several constructors, the exception class itself inherits all methods from its parent class. And the methods associated with the exception are inherited from the Java.lang.Throwable class. and Printstacktrace () is one of them.

This method prints the stack trajectory information of the Throwable object to the standard error output stream. The general appearance of the output is as follows:

1 2 3 4 Java.lang.NullPointerException at Myclass.mash (myclass.java:9) at Myclass.crunch (Myclass.java:6) At Myclass.main (Myclass.java:3)

The first line of output is the output of the ToString () method, followed by a few lines of content that were previously saved by the Fillinstacktrace () method. About this method, we'll talk about it later.

Let's look at an example:

1 2 3 4, 5 6 7 8 9 10 11 12 13 14 15 public class
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.