private void errorDuringTransaction ( final Throwable t , final Method method , final String extraErrorMessage ) throws Throwable { final StringBuilder errorMessageBuilder = new StringBuilder ( "Error during transaction for sql entity {} and method {}" ) ; if ( t instanceof SQLException ) { final SQLException sqlException = ( SQLException ) t ; errorMessageBuilder . append ( " [SQL DefaultState: " ) . append ( sqlException . getSQLState ( ) ) . append ( ", Vendor Error Code: " ) . append ( sqlException . getErrorCode ( ) ) . append ( "]" ) ; } if ( extraErrorMessage != null ) { // This is usually the SQL statement errorMessageBuilder . append ( "\n" ) . append ( extraErrorMessage ) ; } logger . warn ( errorMessageBuilder . toString ( ) , sqlDaoClass , method . getName ( ) ) ; // This is to avoid throwing an exception wrapped in an UndeclaredThrowableException if ( ! ( t instanceof RuntimeException ) ) { throw new RuntimeException ( t ) ; } else { throw t ; } }
Nice method name to ease debugging while looking at log files