public static String getBaseMessage(Throwable exception) {
        String message = null;

        // -----------------------------------------------------------------------
        // RemoteException contains a 'detail' field that holds the 'cause',
        // instead of the normal cause defined by Throwable.  When detail is
        // set, getMessage() will include the text and stack of the detail,
        // which may ends up duplicating the message text.
        //
        // To avoid this, 'detail' is temporarily cleared, resulting in
        // getMessage() returning only the message text specified when the
        // RemoteException was created.                                    d366807
        // -----------------------------------------------------------------------
        if (exception instanceof RemoteException) {
            RemoteException rex = (RemoteException) exception;
            Throwable detail = rex.detail;
            rex.detail = null;

            message = rex.getMessage();

            rex.detail = detail;

            // We frequently create remote exceptions with an empty message
            // to avoid redundant messages being printed in stack traces.  If the
            // remote exception has an empty message, use the detail.       d739198
            if ("".equals(message) && detail != null) {
                message = getBaseMessage(detail);
            }
        }

        // -----------------------------------------------------------------------
        // Other exceptions, like EJBException, do not contain a public field
        // that holds the 'cause'. So for these exceptions, the returned
        // message text is just parsed for the beginning of the nested
        // exceptions... and then truncated.
        // -----------------------------------------------------------------------
        else if (exception != null) {
            message = exception.getMessage();
            if (message != null) {
                if (message.startsWith("nested exception is:")) {
                    message = null;
                } else {
                    int nestIndex = message.indexOf("; nested exception is:");
                    if (nestIndex > -1)
                        message = message.substring(0, nestIndex);
                }
            }
        }
        return message;
    }
public static String getBaseMessage ( Throwable exception ) { String message = null ; if ( exception instanceof RemoteException ) { RemoteException rex = ( RemoteException ) exception ; Throwable detail = rex . detail ; rex . detail = null ; message = rex . getMessage ( ) ; rex . detail = detail ; if ( "" . equals ( message ) && detail != null ) { message = getBaseMessage ( detail ) ; } } else if ( exception != null ) { message = exception . getMessage ( ) ; if ( message != null ) { if ( message . startsWith ( "nested exception is:" ) ) { message = null ; } else { int nestIndex = message . indexOf ( "; nested exception is:" ) ; if ( nestIndex > - 1 ) message = message . substring ( 0 , nestIndex ) ; } } } return message ; }
Returns the 'base' message text of any exception, stripping off all
nested exception text ("nested exception is: etc."). <p>

The getMessage() method of both RemoteException and EJBException have
the helpful/annoying behavior of including the message text/stack for
all nested exceptions as well. This causes duplicate text/stack
information to be logged by WebSphere RAS support, which also includes
the nested exception information. And, all of this can be further
duplicated in the EJB Container mapping code, which converts exceptions
to Remote or Local exceptions, and would like to include the same
message text in the mapped exception... which can result in the
exception text/stack being duplicated 4 or more times. <p>

Also, toString() must be avoided, as it would include the name of
the exception in the message text. <p>

This method will return just the base part of an exceptions message
text... removing all nested exception information. And, it will work
for RemoteException and EJBException, as well as any other Exceptions
that contain similar formatting. <p>