Example usage for java.lang Throwable getCause

List of usage examples for java.lang Throwable getCause

Introduction

In this page you can find the example usage for java.lang Throwable getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.eclipse.cft.server.core.internal.CloudErrorUtil.java

protected static HttpServerErrorException getHttpServerError(Throwable t) {
    if (t == null) {
        return null;
    }/*from  w  w w . j a  va 2 s.com*/
    HttpServerErrorException httpException = null;
    if (t instanceof HttpServerErrorException) {
        httpException = (HttpServerErrorException) t;
    } else {
        Throwable cause = t.getCause();
        if (cause instanceof HttpServerErrorException) {
            httpException = (HttpServerErrorException) cause;
        }
    }
    return httpException;

}

From source file:gov.nasa.ensemble.common.CommonUtils.java

public static Throwable getRootCause(Throwable throwable) {
    final Throwable cause = throwable.getCause();
    if (cause == null)
        return throwable;
    return getRootCause(cause);
}

From source file:com.vmware.bdd.cli.commands.CommandsUtils.java

private static Throwable getRootCause(Exception e) {
    Throwable cause = e.getCause();
    Throwable rootCause = null;//from   w  w  w  .ja  va  2s  .c o  m
    while (cause != null) {
        rootCause = cause;
        cause = cause.getCause();
    }
    return rootCause;
}

From source file:com.xqdev.sql.MLSQL.java

private static void addExceptions(Element meta, Throwable t) {
    if (t == null)
        return;/*from   ww  w . j  ava  2  s.  com*/

    Namespace sql = meta.getNamespace();
    Element exceptions = new Element("exceptions", sql);
    meta.addContent(exceptions);
    do {
        exceptions.addContent(new Element("exception", sql).setAttribute("type", t.getClass().getName())
                .addContent(new Element("reason", sql).setText(t.getMessage())));
        Log.log(t);
        t = t.getCause();
    } while (t != null);
}

From source file:com.cloud.bridge.service.controller.s3.ServiceProvider.java

@SuppressWarnings("unchecked")
private static <T> T getProxy(Class<?> serviceInterface, final T serviceObject) {
    return (T) Proxy.newProxyInstance(serviceObject.getClass().getClassLoader(),
            new Class[] { serviceInterface }, new InvocationHandler() {
                @Override//from ww w  .  ja  v  a 2  s .c o m
                public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                    Object result = null;
                    try {
                        result = method.invoke(serviceObject, args);
                    } catch (Throwable e) {
                        // Rethrow the exception to Axis:
                        // Check if the exception is an AxisFault or a
                        // RuntimeException
                        // enveloped AxisFault and if so, pass it on as
                        // such. Otherwise
                        // log to help debugging and throw as is.
                        if (e.getCause() != null && e.getCause() instanceof AxisFault)
                            throw e.getCause();
                        else if (e.getCause() != null && e.getCause().getCause() != null
                                && e.getCause().getCause() instanceof AxisFault)
                            throw e.getCause().getCause();
                        else {
                            logger.warn("Unhandled exception " + e.getMessage(), e);
                            throw e;
                        }
                    } finally {
                    }
                    return result;
                }
            });
}

From source file:io.appium.java_client.events.DefaultAspect.java

private static Throwable getRootCause(Throwable thrown) {
    Class<? extends Throwable> throwableClass = thrown.getClass();

    if (!InvocationTargetException.class.equals(throwableClass)
            && !RuntimeException.class.equals(throwableClass)) {
        return thrown;
    }/*from   www.j a va  2 s.c  om*/
    if (thrown.getCause() != null) {
        return getRootCause(thrown.getCause());
    }
    return thrown;
}

From source file:com.gs.jrpip.client.FastServletProxyFactory.java

private static boolean isServerDownOrBusy(AuthenticatedUrl url, Throwable e) {
    if (e instanceof ConnectException || e instanceof SocketTimeoutException) {
        LOGGER.error(/*from w  ww  . ja  v  a2 s.  c om*/
                "Looks like the service at {} is down or not responding. Could not determine chunk support.",
                url, e);
        return true;
    }
    if (e.getCause() == null) {
        return false;
    }
    return isServerDownOrBusy(url, e.getCause());
}

From source file:com.codepunk.codepunklib.util.log.FormattingLogger.java

/**
 * Returns the first {@link StackTraceElement} in the stack trace found in <code>tr</code>
 * that was called from outside of this class.
 * @param tr The {@link Throwable} containing the stack trace.
 * @param index The number of levels in the stack trace that result from methods in this class.
 * @return The first significant {@link StackTraceElement}; that is, the first element
 * representing a call made outside of this class.
 *///from w ww.ja  va  2s. co  m
private static StackTraceElement getSignificantStackTraceElement(Throwable tr, int index) {
    StackTraceElement element;
    try {
        if (tr == null) {
            element = (new Throwable()).getStackTrace()[index + 1];
        } else if (tr.getCause() == null) {
            element = tr.getStackTrace()[0];
        } else {
            element = tr.getCause().getStackTrace()[0];
        }
    } catch (Exception e) {
        element = null;
    }
    return element;
}

From source file:at.wada811.dayscounter.CrashExceptionHandler.java

/**
 * ?/*from  www .  ja va2  s. c o m*/
 *
 * @param throwable
 *
 * @return
 *
 * @throws JSONException
 */
public static JSONObject getExceptionInfo(Throwable throwable) throws JSONException {
    JSONObject json = new JSONObject();
    json.put("name", throwable.getClass().getName());
    json.put("message", throwable.getMessage());
    if (throwable.getStackTrace() != null) {
        // ExceptionStacktrace
        JSONArray exceptionStacktrace = new JSONArray();
        for (StackTraceElement element : throwable.getStackTrace()) {
            exceptionStacktrace.put("at " + LogUtils.getMetaInfo(element));
        }
        json.put("ExceptionStacktrace", exceptionStacktrace);
    }
    if (throwable.getCause() != null) {
        json.put("cause", throwable.getCause());
        // CausedStacktrace
        if (throwable.getCause().getStackTrace() != null) {
            JSONArray causedStacktrace = new JSONArray();
            for (StackTraceElement element : throwable.getCause().getStackTrace()) {
                causedStacktrace.put("at " + LogUtils.getMetaInfo(element));
            }
            json.put("CausedStacktrace", causedStacktrace);
        }
    }
    return json;
}

From source file:com.microsoft.alm.plugin.authentication.AuthHelper.java

public static boolean isNotAuthorizedError(final Throwable throwable) {
    //We get VssServiceResponseException when token is valid but does not have the required scopes
    //statusCode on VssServiceResponseException is set to 401 but that is not accessible, so we have to check the message
    //If the message gets localized, we won't detect the auth error
    if (throwable != null
            && (throwable instanceof NotAuthorizedException || (throwable instanceof VssServiceResponseException
                    && StringUtils.containsIgnoreCase(throwable.getMessage(), "unauthorized")))) {
        return true;
    }/*from  w  w w.  j a v a  2  s  . c  om*/

    if (throwable != null && throwable.getCause() != null
            && (throwable.getCause() instanceof NotAuthorizedException
                    || (throwable.getCause() instanceof VssServiceResponseException
                            && (StringUtils.containsIgnoreCase(throwable.getMessage(), "unauthorized"))))) {
        return true;
    }

    return false;
}