Java Reference
In-Depth Information
12.6. Stack Traces
When an exception is created, a stack trace of the call is saved in the
exception object. This is done by the THRowable constructor invoking its
own fillInStacktrace method. You can print this stack trace by using
printStackTrace , and you can replace it with the current stack information
by invoking fillInStackTrace again. If an exception has a cause, then
typically printStackTrace will print the current exceptions stack trace, fol-
lowed by the stack trace of its causehowever, the details of stack trace
printing depend on the virtual-machine implementation.
A stack trace is represented by an array of StackTraceElement objects
that you can get from getStackTrace . You can use this array to examine
the stack or to create your own display of the information. Each Stack-
TraceElement object represents one method invocation on the call stack.
You can query these with the methods getFileName , getClassName , getMeth-
odName , getLineNumber , and isNativeMethod .
You can also set the stack trace with setStackTrace , but you would have
to be writing a very unusual program for this to be a good idea. The real
information contained in a stack trace is quite valuable. Do not discard it
without compelling need. Proper reasons for changing a stack trace are
vital, but very rare.
 
Search WWH ::




Custom Search