开发者

java: printing current backtrace [duplicate]

开发者 https://www.devze.com 2023-02-12 20:14 出处:网络
This question already has answers here: How can I get the current stack trace in Java? (23 answers) Closed 9 years ago.
This question already has answers here: How can I get the current stack trace in Java? (23 answers) Closed 9 years ago.

is there a way to add a command in Java to add the current backtrace ?

I'm writing a red5 application and the appDisconnect function is being called twice. whenever a user changes room. I want to add a f开发者_StackOverflow中文版unction at the beginning of the appDisconnect function that shows the current backtrace and then I can see what called it.

thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消