How can I see a full log of exceptions in JAVA? [duplicate]

ぃ、小莉子 提交于 2019-12-09 10:07:04

问题


When I run some java program with a command java ExceptionTest , exceptions are sometimes omitted and looks like

Exception in thread "main" java.lang.NoClassDefFoundError: aa/bb/DD
        at SOMEWHERE(unknown source)
Caused by: java.lang.ClassNotFoundException: aaa.bbb.CC
        at SOMEWHER(unknown source)
        ... 13 more

I'd like to see 13 more exceptions in this case. Is there an option to see all exception log?


回答1:


You already see them, it's only the ridiculous way Java (and Logback by defaul) prints exceptions by default. This stack trace:

Exception in thread "main" java.lang.NoClassDefFoundError: aa/bb/DD
        at SOMEWHERE(unknown source)
Caused by: java.lang.ClassNotFoundException: aaa.bbb.CC
        at SOMEWHER(unknown source)
        ... 13 more

actually means the following program flow (from bottom to top):

Caused by: java.lang.ClassNotFoundException: aaa.bbb.CC
        at SOMEWHER(unknown source)
Exception in thread "main" java.lang.NoClassDefFoundError: aa/bb/DD
        at SOMEWHERE(unknown source)

The ... 13 more (N common frames omitted in Logback) only means that these exceptions were already printed before. In Logback you can restructure stack track to avoid duplicates and print stack lines always in correct order, see my blog.




回答2:


there aren't 13 more exceptions. There are 13 more lines to the call stack which are identical to previous call stacks, as described here: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Throwable.html#printStackTrace()



来源:https://stackoverflow.com/questions/12226375/how-can-i-see-a-full-log-of-exceptions-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!