Java: print the current return line

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

I am writing a red5 application and the appDisconnect function is called twice. when the user changes the room. I want to add a function at the beginning of the appDisconnect function, which shows the current backtrace, and then I can see what is called.

thanks

+4
source share
2 answers

You can output the stack trace to the current line as follows:

new Exception().printStackTrace(); 

Or, if you need soft keys, stacktrace elements that you can use

 Thread.currentThread().getStackTrace() 
+9
source

The only way I know is to look:

 StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); 

Although this looks more like a logging problem than actually monitoring call tracing. You can also try debug execution in your IDE and add some well-placed breakpoints.

+3
source

Source: https://habr.com/ru/post/1340779/


All Articles