How do I get the current stack trace in Java, like how in .NET you can do Environment.StackTrace?
I found Thread.dumpStack()
but it is not what I want -
Tony, as a comment to the accepted answer, has given what seems to be the best answer which actually answers the OP's question:
Arrays.toString(Thread.currentThread().getStackTrace()).replace( ',', '\n' );
... the OP did NOT ask how to get a String
from the stack trace from an Exception
. And although I'm a huge fan of Apache Commons, when there is something as simple as the above there is no logical reason to use an outside library.