获取Java中的当前堆栈跟踪 [英] Get current stack trace in Java
本文介绍了获取Java中的当前堆栈跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Java中获取当前堆栈跟踪,例如在 .NET 中如何获取可以 Environment.StackTrace
?
How do I get the current stack trace in Java, like how in .NET you can do Environment.StackTrace
?
BTW, Thread.dumpStack()
不是什么我想 - 我想要恢复堆栈跟踪,而不是打印出来。
BTW, Thread.dumpStack()
is not what I want - I want to get the stack trace back, not print it out.
推荐答案
您可以使用 主题 .currentThread()。getStackTrace()
。
You can use Thread.currentThread().getStackTrace()
.
返回 StackTraceElement
表示程序的当前堆栈跟踪。
That returns an array of StackTraceElement
s that represent the current stack trace of a program.
这篇关于获取Java中的当前堆栈跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文