Tag: exception throwable fillinstacktrace
The fillinstacktrace method is used to trace back to the bottom of the stack.
Reprinted a test class:
<Span style = "font-family: Microsoft yahei; font-size: 14px;"> package COM. exception;/*** created with intellij idea. * User: * Date: 14-7-7 * Time: * to change this template use file | Settings | file templates. */class exception2 {throwable th = new throwable (); Public exception2 () {system. out. println ("in constructor");} public void a () {C ();} public void B () {system. out. println ("in B"); th. fillinstacktrace (); th. printstacktrace (system. out); system. out. println ("in B");} public void C () {B (); th. fillinstacktrace (); system. out. println ("in C"); th. printstacktrace (system. out); system. out. println ("in C");} public static void main (string [] ARGs) {exception2 T3 = new exception2 (); t3.a () ;}</span>The execution sequence of the above Code is main () → A () → B () → C ()
The output is as follows:
In Constructor
In B
Java. Lang. throwable
At com. Exception. exception2. B (exception2.java: 23)
At com. Exception. exception2.c (exception2.java: 29)
At com. Exception. exception2.a (exception2.java: 18)
At com. Exception. exception2.main (exception2.java: 40)
At sun. Reflect. nativemethodaccessorimpl. invoke0 (native method)
At sun. Reflect. nativemethodaccessorimpl. Invoke (nativemethodaccessorimpl. Java: 39)
At sun. Reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. Java: 25)
At java. Lang. Reflect. method. Invoke (method. Java: 597)
At com.intellij.rt.exe cution. application. appmain. Main (appmain. Java: 120)
In B
In C
Java. Lang. throwable
At com. Exception. exception2.c (exception2.java: 30)
At com. Exception. exception2.a (exception2.java: 18)
At com. Exception. exception2.main (exception2.java: 40)
At sun. Reflect. nativemethodaccessorimpl. invoke0 (native method)
At sun. Reflect. nativemethodaccessorimpl. Invoke (nativemethodaccessorimpl. Java: 39)
At sun. Reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. Java: 25)
At java. Lang. Reflect. method. Invoke (method. Java: 597)
At com.intellij.rt.exe cution. application. appmain. Main (appmain. Java: 120)
In C
If you comment out fillinstacktrace, the output result is:
In Constructor
In B
Java. Lang. throwable
At com. Exception. exception2. <init> (exception2.java: 11)
At com. Exception. exception2.main (exception2.java: 32)
At sun. Reflect. nativemethodaccessorimpl. invoke0 (native method)
At sun. Reflect. nativemethodaccessorimpl. Invoke (nativemethodaccessorimpl. Java: 39)
At sun. Reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. Java: 25)
At java. Lang. Reflect. method. Invoke (method. Java: 597)
At com.intellij.rt.exe cution. application. appmain. Main (appmain. Java: 120)
In B
In C
Java. Lang. throwable
At com. Exception. exception2. <init> (exception2.java: 11)
At com. Exception. exception2.main (exception2.java: 32)
At sun. Reflect. nativemethodaccessorimpl. invoke0 (native method)
At sun. Reflect. nativemethodaccessorimpl. Invoke (nativemethodaccessorimpl. Java: 39)
At sun. Reflect. delegatingmethodaccessorimpl. Invoke (delegatingmethodaccessorimpl. Java: 25)
At java. Lang. Reflect. method. Invoke (method. Java: 597)
At com.intellij.rt.exe cution. application. appmain. Main (appmain. Java: 120)
In C