java - 发生异常时显示完整的堆栈跟踪

标签 java exception tomcat logging stack-trace

<分区>

Possible Duplicate:
howto increase lines of java stack trace dump?

我正在为 tomcat 编写一个 Java 应用程序。每当抛出异常时,我都会得到异常的名称和堆栈跟踪,最后如果跟踪很长,我会得到 ... X 更多

如何配置 tomcat 以显示完整的堆栈跟踪?

谢谢!

最佳答案

这不是 Tomcat 的错,这是 Throwable.printStackTraceAsCause(PrintStream s, StackTraceElement[] causedTrace) 方法实现堆栈跟踪打印的方式。

 /**
     * Print our stack trace as a cause for the specified stack trace.
     */
    private void printStackTraceAsCause(PrintStream s,
                                        StackTraceElement[] causedTrace)
    {
        // assert Thread.holdsLock(s);

        // Compute number of frames in common between this and caused
        StackTraceElement[] trace = getOurStackTrace();
        int m = trace.length-1, n = causedTrace.length-1;
        while (m >= 0 && n >=0 && trace[m].equals(causedTrace[n])) {
            m--; n--;
        }
        int framesInCommon = trace.length - 1 - m;

        s.println("Caused by: " + this);
        for (int i=0; i <= m; i++)
            s.println("\tat " + trace[i]);
        if (framesInCommon != 0)
            s.println("\t... " + framesInCommon + " more");

        // Recurse if we have a cause
        Throwable ourCause = getCause();
        if (ourCause != null)
            ourCause.printStackTraceAsCause(s, trace);
    }

如果需要,您可以通过首先显示捕获元素的消息,然后显示 StackTraceElement(可通过调用Throwable.getStackTrace() 方法找到)。

关于java - 发生异常时显示完整的堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6691150/

相关文章:

java - jnlp href 属性中的 url 参数

apache-flex - 加载声音会在Sound.id3上给出异常

java - 运行时异常无法启动 MainActivity

PHP try-catch 不工作

java - Spring Boot SSL已配置,服务器已启动但无法连接到端口

java - 如何防止tomcat session 劫持?

java - Spring、Bean、构造函数参数作为字符串

java - 在 Eclipse 中执行 SQL 查询时出错

java - 在avice周围,如何获取advice方法的参数 'type parameter'

java - Eclipse Java 远程调试 : How do I ensure that the code I've got in my project is the same as the code running in the JVM?