如何获取Java中的当前堆栈跟踪? [英] How can I get the current stack trace in Java?
本文介绍了如何获取Java中的当前堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Java中获取当前的堆栈跟踪,就像在.NET中一样 Environment.StackTrace
?>
我找到了Thread.dumpStack()
,但这不是我想要的-我想找回堆栈跟踪信息,而不是将其打印出来.
解决方案
您可以使用Thread.currentThread().getStackTrace()
.
返回一个数组 StackTraceElement
代表程序当前堆栈跟踪的a>.
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.
解决方案
You can use Thread.currentThread().getStackTrace()
.
That returns an array of StackTraceElement
s that represent the current stack trace of a program.
这篇关于如何获取Java中的当前堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文