Java Stacktrace 中断太早
Java Stacktrace cuts off too soon
有时我在堆栈跟踪中有一个长链(由 x 引起,由 y 引起),在它到达我怀疑是好的部分之前突然切断。好的部分是我编写并控制的代码,而不是我正在使用的各种经过改进的第三方代码(服务器、JSP 等),它们可能不包含错误。堆栈跟踪将以类似以下内容结束:
....and 70 more.
遇到这种情况我该怎么办?有没有办法告诉 Java 共享更完整的堆栈跟踪?
我在 Eclipse 中工作。
没有,但是,线索是,堆栈跟踪仍然存在。
这个 ... 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个?他们是:
at Example.foo(Example.java:7)
at Example.main(Example.java:3)
-- 'Cause' 导致 ('Actual') 的相同两行以结尾。
有时我在堆栈跟踪中有一个长链(由 x 引起,由 y 引起),在它到达我怀疑是好的部分之前突然切断。好的部分是我编写并控制的代码,而不是我正在使用的各种经过改进的第三方代码(服务器、JSP 等),它们可能不包含错误。堆栈跟踪将以类似以下内容结束:
....and 70 more.
遇到这种情况我该怎么办?有没有办法告诉 Java 共享更完整的堆栈跟踪?
我在 Eclipse 中工作。
没有,但是,线索是,堆栈跟踪仍然存在。
这个 ... 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个?他们是:
at Example.foo(Example.java:7)
at Example.main(Example.java:3)
-- 'Cause' 导致 ('Actual') 的相同两行以结尾。