Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
384 views
in Technique[技术] by (71.8m points)

stack-trace - 如何获得Java中的当前堆栈跟踪?(How can I get the current stack trace in Java?)

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

(我如何在Java中获取当前的堆栈跟踪 ,例如在.NET中如何执行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.

(我找到了Thread.dumpStack()但这不是我想要的-我想获取堆栈跟踪,而不是打印出来。)

  ask by ripper234 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

(您可以使用Thread.currentThread().getStackTrace() 。)

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

(这将返回一个StackTraceElement数组,该数组代表程序的当前堆栈跟踪。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...