Fillinstacktrace in throwable

Source: Internet
Author: User

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

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.