public static String exceptionList ( Throwable ex ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "<=================================>" ) ; sb . append ( "Exception Message -> " ) ; sb . append ( ex . getMessage ( ) ) ; sb . append ( nl ) ; if ( ex instanceof ResourceException ) { sb . append ( " ResourceException Error Code -> " ) ; sb . append ( ( ( ResourceException ) ex ) . getErrorCode ( ) ) ; sb . append ( nl ) ; } if ( ex instanceof SQLException ) { sb . append ( " SQLException Error Code -> " ) ; sb . append ( ( ( SQLException ) ex ) . getErrorCode ( ) ) ; sb . append ( nl ) ; sb . append ( " SQLException SQLState -> " ) ; sb . append ( ( ( SQLException ) ex ) . getSQLState ( ) ) ; sb . append ( nl ) ; } // Get stack trace of current exception StringWriter sw = new StringWriter ( ) ; PrintWriter pw = new PrintWriter ( sw ) ; ex . printStackTrace ( pw ) ; sb . append ( sw . getBuffer ( ) ) ; sb . append ( "<=================================>" ) ; // If exception supports linked exceptions, get linked exception Throwable ex2 = null ; ex2 = ex . getCause ( ) ; // If we got a linked exception, recursively call this method if ( ex2 != null ) { sb . append ( "Next Linked Exception:" + nl ) ; sb . append ( exceptionList ( ex2 ) ) ; } return sb . toString ( ) ; }
Method which prints the stack trace of exception and any linked exceptions .