How to print stack trace for stdout in java for debugging?

I am new to java.

I need something like debug_print_backtrace in java.

I want to print the current stack trace in stdout or in intellij log log window for debugging.

I used debug_print_backtrace in php to find stack information at runtime for debugging.

+4
source share
2 answers

You only need one line.

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

Thanks Get current stack trace in Java

trace the stack trace of stderr :

new Exception().printStackTrace();
+4
source

Instead of printing to the console, use javax.swing.JOptionPane.showMessageDialog (null, new Exception (). PrintStackTrace ());

0
source

All Articles