HiveBrain v1.2.0
Get Started
← Back to all entries
debugjavaCritical

How can I get the current stack trace in Java?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howtracejavathecurrentstackcanget

Problem

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 - I want to get the stack trace back, not print it out.

Solution

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

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

Context

Stack Overflow Q#1069066, score: 1318

Revisions (0)

No revisions yet.