java: printing current backtrace

This question already has an answer here:

  • Get current stack trace in Java 21 answers

  • 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.

    链接地址: http://www.djcxy.com/p/82406.html

    上一篇: 在程序中的任何位置生成Java堆栈跟踪

    下一篇: java:打印当前回溯