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 -
Thread.dumpStack()
In Java 9 there is a new way:
public static void showTrace() { List frames = StackWalker.getInstance( Option.RETAIN_CLASS_REFERENCE ) .walk( stream -> stream.collect( Collectors.toList() ) ); for ( StackFrame stackFrame : frames ) System.out.println( stackFrame ); }