java: printing current backtrace
This question already has an answer here:
You can output the stack trace to the current line like this:
new Exception().printStackTrace();
Or if you need programmattic acces the the stacktrace elements you can use
Thread.currentThread().getStackTrace()
The only way I know of is to look at:
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
Although this sounds more like a logging
issue than actually observing the call trace. You could also try to setup debug
execution in your IDE and add a few well placed breakpoints.
上一篇: 在程序中的任何位置生成Java堆栈跟踪
下一篇: java:打印当前回溯