How to dump the stack trace into IntelliJ console (not log file)?
I am trying to print the stack trace for a passive breakpoint (suspend = none) and not able to. The eval expr field expects a string. If I put printStacktrace or Thread.dumpStack(), both return void so the ST won't show up in the console. Short of creating a static utility method that returns the ST as a string, is there a more elegant way to dump the ST in the console in IntelliJ ?
Please sign in to leave a comment.
I do not believe there is a built in way to do this. I can suggest the following two options.
Option 1
You could Print the value (which is an array) of the getStackTrace() method. The Log Evaluated Expression field will handle the a Sting array as well as a String.
The downside here is that the stack trace will be comma delimited single line:
This can make it much harder to read, especially on a long stack trace. And you do not get the exception's message, just the stack trace. Given your use case, the lost of the message is likely not a big deal.
As an FYI, if you want a String value so you can concatenate to another message, you could always wrap it in a call to Arrays.toString()
Option 2
To get a "standard" stack trace as a single string, you can use the getStackTrace() method of the ExceptionUtils class from the Apache Commons Lang library:
That would result in a conventional stack trace output:
That would of course mean you need to have the Commons Lang library as a dependency. Given its usefulness, and compact size, that is hopefully not an issue.
I hope that helps.