static public Throwable findRootCause ( Throwable throwable ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) { Tr . entry ( tc , "findRootCause: " + throwable ) ; } Throwable root = throwable ; Throwable next = root ; while ( next != null ) { root = next ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "finding cause of: " + root . getClass ( ) . getName ( ) ) ; } if ( root instanceof java . rmi . RemoteException ) { next = ( ( java . rmi . RemoteException ) root ) . detail ; } else if ( root instanceof WsNestedException ) // d162976 { next = ( ( WsNestedException ) root ) . getCause ( ) ; // d162976 } else if ( root instanceof TransactionRolledbackLocalException ) //d180095 begin { next = ( ( TransactionRolledbackLocalException ) root ) . getCause ( ) ; } else if ( root instanceof AccessLocalException ) { next = ( ( AccessLocalException ) root ) . getCause ( ) ; } else if ( root instanceof NoSuchObjectLocalException ) { next = ( ( NoSuchObjectLocalException ) root ) . getCause ( ) ; } else if ( root instanceof TransactionRequiredLocalException ) { next = ( ( TransactionRequiredLocalException ) root ) . getCause ( ) ; } // else if (root instanceof InvalidActivityLocalException) // { // root = ((InvalidActivityLocalException) root).getCause(); // } // else if (root instanceof ActivityRequiredLocalException) // { // root = ((ActivityRequiredLocalException) root).getCause(); // } // else if (root instanceof ActivityCompletedLocalException) // { // next = ((ActivityCompletedLocalException) root).getCause(); //d180095 end // } else if ( root instanceof NamingException ) { next = ( ( NamingException ) root ) . getRootCause ( ) ; } else if ( root instanceof InvocationTargetException ) { next = ( ( InvocationTargetException ) root ) . getTargetException ( ) ; } else if ( root instanceof org . omg . CORBA . portable . UnknownException ) { next = ( ( org . omg . CORBA . portable . UnknownException ) root ) . originalEx ; } else if ( root instanceof InjectionException ) // d436080 { next = root . getCause ( ) ; } else { next = null ; } } if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isEntryEnabled ( ) ) Tr . exit ( tc , "findRootCause returning: " + root ) ; return root ; }
Finds the root cause of a Throwable that occured . This routine will continue to look through chained Throwables until it cannot find another chained Throwable and return the last one in the chain as the root cause .