13

I am new to java.

I want something like debug_print_backtrace in java.

I want to print current stack trace to stdout or to intellij idea log window for debug.

I used to use debug_print_backtrace in php to find some stack infos in runtime for debug.

1
  • 1
    I add this question for google searching in case I forgot how to do that, so when I search "java print stack trace", I can get what I want right away. Commented Oct 9, 2014 at 17:34

2 Answers 2

24

You only need one line.

new Exception().printStackTrace(System.out);

Thanks to Get current stack trace in Java

print stack trace to stderr:

new Exception().printStackTrace();
Sign up to request clarification or add additional context in comments.

2 Comments

This goes to stderr. If you want to have it in stdout: new Exception().printStackTrace(System.out);
@ROMANIA_engineer I always think stderr and stdout is almost the same stuff. Thanks for your correct.
-3

Instead of printing in console, use this javax.swing.JOptionPane.showMessageDialog(null,new Exception().printStackTrace());

1 Comment

I am using java in android. It just do not have the package of javax.swing .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.