Java堆栈跟踪截断得太早。

huangapple go评论83阅读模式
英文:

Java Stacktrace cuts off too soon

问题

有时候在堆栈跟踪中会出现一长串的链条(由 x 引起,由 y 引起),在到达我认为是关键部分之前突然中断。 关键部分是我编写并且有控制权的代码,而不是我使用的各种经过优化的第三方代码(服务器,JSP 等),这些代码可能不包含错误。 堆栈跟踪最后会以以下方式结束:

> .... 还有 70 行。

在这种情况下我该怎么办? 有没有办法告诉 Java 共享更完整的堆栈跟踪?

我在 Eclipse 中工作。

英文:

Sometimes I have a long chain (caused by x, caused by y) in a stack trace that abruptly cuts off before it gets to what I suspect is the good part. The good part being the code I've written and have control over and not the various refined third party code I'm using (server, JSP, etc.) that probably doesn't contain an error. The stack trace will end with something like:

> ....and 70 more.

What can I do in this situation? Is there a way to tell Java to share a fuller stack trace?

I'm working in Eclipse.

答案1

得分: 4

没有,但是关键是,堆栈跟踪仍然存在。

这个 ... 70 more. 的东西缩写为: "… 从这里开始,与我导致的东西相同"。

所以,只需向上滚动一个异常,然后查看那个异常的底部 70 行。(也许是 20 行堆栈跟踪,然后是 '… 和其他 50 行',在这种情况下,反复应用这个原则)。

简单测试:

class Example {
    public static void main(String[] args) {
        foo();
    }

    static void foo() {
        bar();
    }

    static void bar() {
        try {
            throw new RuntimeException("Cause");
        } catch (Exception e) {
            throw new RuntimeException("Actual", e);
        }
    }
}

这将打印出:

Exception in thread "main" java.lang.RuntimeException: Actual
	at Example.bar(Example.java:14)
	at Example.foo(Example.java:7)
	at Example.main(Example.java:3)
Caused by: java.lang.RuntimeException: Cause
	at Example.bar(Example.java:12)
	... 2 more

你可以手动计算正确的堆栈跟踪,因为示例非常简单。那个 "2 more"?它们是:

	at Example.foo(Example.java:7)
	at Example.main(Example.java:3)

-- 与 'Cause' 所导致的事物 ('Actual') 的最后两行相同。

英文:

There isn't, but, the clue is, the stacktrace is still there.

This ... 70 more. stuff is short for: "... and from here it is the same as the thing I am the cause of".

So, just scroll up one exception and look at the bottom 70 lines of that one. (and maybe that's 20 stacktrace lines and then '... and 50 more', in which case, repeatedly apply this principle).

Simple test:

class Example {
    public static void main(String[] args) {
        foo();
    }

    static void foo() {
        bar();
    }

    static void bar() {
        try {
            throw new RuntimeException("Cause");
        } catch (Exception e) {
            throw new RuntimeException("Actual", e);
        }
    }
}

this prints:

Exception in thread "main" java.lang.RuntimeException: Actual
	at Example.bar(Example.java:14)
	at Example.foo(Example.java:7)
	at Example.main(Example.java:3)
Caused by: java.lang.RuntimeException: Cause
	at Example.bar(Example.java:12)
	... 2 more

You can calculate the proper stacktrace by hand because the example is so simple. Those 2 more? They are:

	at Example.foo(Example.java:7)
	at Example.main(Example.java:3)

-- the same 2 lines that the thing that 'Cause' was the cause of ('Actual') end with.

huangapple
  • 本文由 发表于 2020年8月26日 03:02:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/63585511.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定