Example usage for org.apache.commons.lang3.exception ExceptionUtils getThrowables

List of usage examples for org.apache.commons.lang3.exception ExceptionUtils getThrowables

Introduction

In this page you can find the example usage for org.apache.commons.lang3.exception ExceptionUtils getThrowables.

Prototype

public static Throwable[] getThrowables(final Throwable throwable) 

Source Link

Document

Returns the list of Throwable objects in the exception chain.

A throwable without cause will return an array containing one element - the input throwable.

Usage

From source file:ch.cyberduck.core.DefaultIOExceptionMappingService.java

@Override
public BackgroundException map(final IOException failure) {
    final Throwable[] stack = ExceptionUtils.getThrowables(failure);
    for (Throwable t : stack) {
        if (t instanceof BackgroundException) {
            return (BackgroundException) t;
        }/*from  w  w  w.  j a v  a 2  s  .  c o  m*/
    }
    if (failure instanceof SSLException) {
        return new SSLExceptionMappingService().map((SSLException) failure);
    }
    final StringBuilder buffer = new StringBuilder();
    this.append(buffer, failure.getMessage());
    for (Throwable cause : ExceptionUtils.getThrowableList(failure)) {
        if (!StringUtils.contains(failure.getMessage(), cause.getMessage())) {
            this.append(buffer, cause.getMessage());
        }
    }
    return this.wrap(failure, buffer);
}

From source file:org.craftercms.security.processors.impl.SecurityExceptionProcessor.java

public SecurityProviderException findSecurityException(Exception topException) {
    Throwable[] exceptionChain = ExceptionUtils.getThrowables(topException);
    for (Throwable e : exceptionChain) {
        if (e instanceof SecurityProviderException) {
            return (SecurityProviderException) e;
        }/*  www. j  av  a2  s  .c o m*/
    }

    return null;
}

From source file:org.siphon.common.js.JsEngineUtil.java

/**
 * ? js new Error new   ? js  java ? /*w  w  w . j av a  2s . co  m*/
 * @return  js  name  value  Scriptable java   throwable
 */
public static Object parseJsException(Throwable e) {
    for (Throwable throwable : ExceptionUtils.getThrowables(e)) {
        if (throwable instanceof ECMAException) {
            ECMAException je = (ECMAException) throwable;
            if (je.thrown != null) {
                Object thrown = je.thrown;
                if (thrown instanceof Throwable) {
                    return parseJsException((Throwable) thrown);
                } else if (thrown instanceof NativeError) {
                    return thrown;
                    //                  Object nashornException = ((NativeError) thrown).nashornException;
                    //                  if (nashornException != null) {
                    //                     if (nashornException instanceof Throwable) {
                    //                        return parseJsException((Throwable) nashornException);
                    //                     } else {
                    //                        return nashornException;
                    //                     }
                    //                  } else {
                    //                     return thrown;
                    //                  }
                } else {
                    return thrown;
                }
            }
        }
    }
    return e;
}

From source file:uk.q3c.krail.core.shiro.KrailErrorHandler.java

@Override
public void error(ErrorEvent event) {
    Throwable originalError = event.getThrowable();

    // handle an attempt to navigate to an invalid page
    int invalidURI = ExceptionUtils.indexOfThrowable(originalError, InvalidURIException.class);
    if (invalidURI >= 0) {
        InvalidURIException e = (InvalidURIException) ExceptionUtils.getThrowables(originalError)[invalidURI];
        invalidUriHandler.invoke(e);//from  w ww .ja  va2s  .co  m
        return;
    }

    // handle an unauthenticated access attempt
    int unauthenticated = ExceptionUtils.indexOfThrowable(originalError, UnauthenticatedException.class);
    if (unauthenticated >= 0) {
        authenticationHandler.invoke();
        return;
    }

    // handle an unauthorised access attempt
    int unauthorised = ExceptionUtils.indexOfThrowable(originalError, UnauthorizedException.class);
    if (unauthorised >= 0) {
        authorisationHandler.invoke();
        return;
    }

    navigator.error(event.getThrowable());

}