如何增加 Java 堆栈跟踪转储的显示行数? [英] How do I increase the number of displayed lines of a Java stack trace dump?

查看:30
本文介绍了如何增加 Java 堆栈跟踪转储的显示行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 Throwable.printStackTrace(PrintStream s) 打印完整的堆栈跟踪,以便我可以看到 的最后一行之外的内容... 40 more"?

推荐答案

你不需要;该信息存在于堆栈跟踪中的其他地方.来自 printStackTrace 的文档():

You don't need to; that information is present elsewhere in the stack trace. From the docs of printStackTrace():

注意包含字符 "..." 的行的存在.这些行表示此异常的堆栈跟踪的其余部分与由此异常(封闭"异常)引起的异常的堆栈跟踪底部的指定帧数相匹配.

Note the presence of lines containing the characters "...". These lines indicate that the remainder of the stack trace for this exception matches the indicated number of frames from the bottom of the stack trace of the exception that was caused by this exception (the "enclosing" exception).

这种简写可以大大减少输出的长度,在常见情况下,从与原因异常"相同的方法抛出一个包装的异常.被抓住了.

This shorthand can greatly reduce the length of the output in the common case where a wrapped exception is thrown from same method as the "causative exception" is caught.

换句话说,... x more" 只出现在链式异常上,并且只有当堆栈跟踪的最后 x 行已经作为另一个链式异常堆栈跟踪的一部分出现.

In other words, the "... x more" only appears on a chained exception, and only when the last x lines of the stack trace are already present as part of another chained exception's stack trace.

假设一个方法捕获了异常Foo,将其包裹在异常Bar中,然后抛出Bar.然后 Foo 的堆栈跟踪将被缩短.如果您出于某种原因想要完整的跟踪,您需要做的就是在 Foo 的堆栈跟踪中 ... 之前的最后一行,并在 Bar 的堆栈跟踪中查找它;该行下方的所有内容都将在 Foo 的堆栈跟踪中打印出来.

Suppose that a method catches exception Foo, wraps it in exception Bar, and throws Bar. Then Foo's stack trace will be shortened. If you for some reason want the full trace, all you need to do is take the last line before the ... in Foo's stack trace and look for it in the Bar's stack trace; everything below that line is exactly what would have been printed in Foo's stack trace.

这篇关于如何增加 Java 堆栈跟踪转储的显示行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆