private static GuacamoleException toGuacamoleException(String message,
            Throwable cause) {

        // Create generic invalid username/password exception if we have no
        // specific cause
        if (cause == null)
            return new GuacamoleInvalidCredentialsException(
                "Permission Denied.",
                CredentialsInfo.USERNAME_PASSWORD
            );

        // If the specific cause is already a GuacamoleException, there's
        // nothing for us to do here
        if (cause instanceof GuacamoleException)
            return (GuacamoleException) cause;

        // Wrap all other Throwables as generic internal errors
        return new GuacamoleServerException(message, cause);

    }
Converts the given Throwable to a GuacamoleException representing the
failure that occurred. If the Throwable already is a GuacamoleException,
this will just be that Throwable. For all other cases, a new
GuacamoleException will be created that best represents the provided
failure. If no failure is provided at all, a generic
GuacamoleInvalidCredentialsException requesting a username/password is
created.

@param message
    A human-readable message describing the failure that occurred.

@param cause
    The Throwable cause of the failure that occurred, if any, or null if
    the cause is not known to be a specific Throwable.

@return
    A GuacamoleException representation of the message and cause
    provided.
guacamole/src/main/java/org/apache/guacamole/rest/auth/GuacamoleAuthenticationProcessException.java