Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Java by (4k points)

How do I get the current stack trace in Java, like how in .NETyou can do Environment.StackTrace?

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

1 Answer

0 votes
by (46k points)

To get a current stack trace in JAVA useThread.currentThread().getStackTrace()

Example:

for (StackTraceElement ste : Thread.currentThread().getStackTrace())

 {

    System.out.println(ste);

}

This Returns an array of StackTraceElement, each array represents one stack frame.

To learn more about it click here.

Related questions

0 votes
1 answer
asked Jul 9, 2019 in Java by Aditya98 (1.3k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...