且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取Java中的当前堆栈跟踪?

更新时间:2023-12-03 23:27:40

您可以使用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 StackTraceElements that represent the current stack trace of a program.