我找到了Thread.dumpStack(),但这不是我想要的-我想找回堆栈跟踪信息,而不是将其打印出来.解决方案您可以使用Thread.currentThread().getStackTrace().返回一个数组 StackTraceElement .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. 这篇关于如何获取Java中的当前堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-04 19:59