When the program has stopped at a breakpoint, I want to copy the current stack trace (the call stack) and paste it into a text file.
Unfortunately, the current version of IntelliJ Idea does not provide such functionality in the debugger frames window.
The printStackTrace() method of Java. lang. Throwable class used to print this Throwable along with other details like class name and line number where the exception occurred means its backtrace. This method prints a stack trace for this Throwable object on the standard error output stream.
Usage. When stopped at breakpoint while debugging, you can right click on a variable and select "Copy as JSON String". The selected variable will be serialized to JSON and get copied to your clipboard.
You can obtain a stack trace from a thread – by calling the getStackTrace method on that Thread instance. This invocation returns an array of StackTraceElement, from which details about stack frames of the thread can be extracted.
You can use:
The solution is to add a special watch (the green + in the Variables window of the debugger), either
new Exception("debug").getStackTrace()
or
org.apache.commons.lang.StringUtils.join(new Exception("debug").getStackTrace(),"\n")
It is possible to copy (and paste as text) the value of such watch, and this value is the stack trace.
(You should be able to use String.join() in Java 8 or TextUtils.join(delimiter, array) in Android)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With