How do I stop stacktraces truncating in logs

后端 未结 6 1336
逝去的感伤
逝去的感伤 2020-11-27 17:39

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

Caused by: java.sql.BatchUpdateException: failed batch
    at org.hsqldb.jdbc.jdbcStatement.executeBatch         


        
6条回答
  •  悲哀的现实
    2020-11-27 18:03

    I found this useful to get the whole picture. Get a full stack trace of the Exception and the cause (which often shows repeated lines from the main Exception, but can be helpful).

            ... catch( Exception e) ...
    
            ... catch( NoClassDefFoundError e)
            {
    
                    for(StackTraceElement ste: e.getStackTrace())
                    {
                        System.out.println(ste);
                    }
    
                    if( e.getCause()!=null )
                    {
                        for(StackTraceElement ste: e.getCause().getStackTrace())
                        {
                            System.out.println(ste);
                        }
                    }
            }
    

提交回复
热议问题