Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 679
aqjune Avatar asked Sep 01 '12 08:09

aqjune


Video Answer


2 Answers

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.

like image 96
Tomasz Nurkiewicz Avatar answered Nov 14 '22 20:11

Tomasz Nurkiewicz


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()

like image 40
Jens Schauder Avatar answered Nov 14 '22 20:11

Jens Schauder