ripper234 ripper234 - 5 months ago 14
Java Question

Get current stack trace in Java

How do I get the current stack trace in Java, like how in .NET you can do

?

BTW,
Thread.dumpStack()
is not what I want - I want to get the stack trace back, not print it out.

Answer

You can use Thread.currentThread().getStackTrace().

That returns an array of StackTraceElements that represent the current stack trace of a program.

Comments