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 |