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