tags:

views:

586

answers:

2

Lots of times in Java logs I'll get something like:

Caused by: java.sql.BatchUpdateException: failed batch
    at org.hsqldb.jdbc.jdbcStatement.executeBatch(jdbcStatement.java:1102)
    at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(jdbcPreparedStatement.java:514)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
    ... 113 more

Does anyone know how to get the full stacktrace showing (i.e. show the other 113 lines)?


The JavaDocs for Throwable have a pretty detailed explanation of what's going on.

+9  A: 

When you see '...113 more', that means that the remaining lines of the 'caused by' exception are identical to the remaining lines from that point on of the parent exception.

For example, you'll have

com.something.XyzException
  at ...
  at ...
  at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
  at ... <the other 113 lines are here>...
Caused by: <the above>.

The two stack traces 'meet' at AbstractBatcher.executeBatch, line 242, and then from then on the upward call trace is the same as the wrapping exception.

Cowan
What? The cause is the same as the wrapping exception? I didn't got it... The couse should show the line where the problem is from, what it not showing when truncating the stacktrace. I'm having this problem and would like to understand this answer, if someone could reformulate it... Thanks! By the way, this answer seem not to show how to print the full stacktrace.
Tom Brito
@TomBrito you ARE seeing the full stacktrace -- you have two exceptions, one inside the other. If the stack trace of the inner (wrapped) exception is A B C D E F G, and the outer exception's stack trace is A B C Z, then you'll see OuterException with the stack trace Z C B A, "caused by" InnerException with the stack trace "G F E D C ... 'then 2 more'". Those 2 more are A and B, from the outer stack trace, and they are ommitted for brevity.
Cowan
@Cowan got it, thanks!
Tom Brito
+4  A: 

Apache's Commons Lang provides a nice util method ExceptionUtils.printRootCauseStackTrace() which prints a nested stacktrace 'upside down'. The result is much more intuitive.

If you see the result next to the original out of the printStackTrace() method, it will be clear where the '113 more' lines went.

Hes Siemelink