The Printstacktrace () method in Java __java

Source: Internet
Author: User
Tags java throws

try{...
}
catch (Exception e)
{
e.printstacktrace ();
}

When an exception occurs in a try statement, the statement in the catch is executed, and the Java Run-time system automatically initializes the exception e in the catch bracket, that is, instantiating the object of the exception type. E is the name of this object exception. Then e (reference) automatically invokes the method specified in the exception class, and there is a e.printstacktrace ();. The Printstacktrace () method means the location and cause of the error in the program where the exception information is printed on the command line. (This is the vernacular explanation, relatively easy to understand)


Java throws exceptions in a number of ways, including the two most commonly used:
System.out.println (e), this method prints out the exception, and the output where the exception, but it and another e.printstacktrace () method is different. The latter also prints out the exception, but it will also show deeper invocation information.
For example:
A extends---> B extends----> C
When a problem occurs during the creation of a, we throw an exception.
System.out.println (e), in addition to the standard exception, only print at A and then output to the outer layer.
E.printstacktrace (), in addition to standard exceptions, print
At C
At B
At A
....... Investigate the outer layer again.
In the case of investigation to the outer layer, the same. I'll go back to Com.sun.midp.main.Main.main in the end

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.