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:Main.java

/**
 * Check the given Throwable and recursively his cause to in order to find
 * an InterruptedException instance. If found, the exception is rethrown and
 * the current Thread is interrupted.// w w  w.  j  a va 2s . c o  m
 * 
 * @param thw
 * @throws InterruptedException
 */
public static void checkInterrupted(Throwable thw) throws InterruptedException {
    while (thw != null) {
        if (thw instanceof InterruptedException) {
            Thread.currentThread().interrupt();
            throw (InterruptedException) thw;
        }
        thw = thw.getCause();
    }
}

From source file:com.android.tools.idea.diagnostics.crash.CrashReport.java

@NotNull
public static Throwable getRootCause(@NotNull Throwable t) {
    int depth = 0;
    while (depth++ < 20) {
        if (t.getCause() == null)
            return t;
        t = t.getCause();/*w ww.ja  va  2  s  .  c om*/
    }
    return t;
}

From source file:at.ac.univie.isc.asio.insight.VndError.java

/**
 * Circular reference safe root finder./*from ww w . j a v  a  2 s.  c o m*/
 *
 * @param throwable any non-null exception
 * @return root exception or an AssertionError if a circular reference is detected
 */
private static Throwable findRoot(Throwable throwable) {
    final Set<Throwable> seen = Sets.newIdentityHashSet();
    seen.add(throwable);
    Throwable cause;
    while ((cause = throwable.getCause()) != null) {
        throwable = cause;
        if (!seen.add(throwable)) {
            return circularPlaceholder(throwable);
        }
    }
    return throwable;
}

From source file:griffon.util.GriffonUtil.java

/**
 * <p>Extracts the root cause of the exception, no matter how nested it is</p>
 * @param t the throwable to sanitize/*from   w  ww. ja  v  a  2 s  .c o  m*/
 * @return The deepest cause of the exception that can be found
 */
public static Throwable extractRootCause(Throwable t) {
    Throwable result = t;
    while (result.getCause() != null) {
        result = result.getCause();
    }
    return result;
}

From source file:griffon.util.GriffonUtil.java

/**
 * <p>Sanitize the exception and ALL nested causes</p>
 * <p>This will MODIFY the stacktrace of the exception instance and all its causes irreversibly</p>
 * @param t//from   ww  w  . ja va 2  s . c o  m
 * @return The root cause exception instances, with stack trace modified to filter out griffon runtime classes
 */
public static Throwable deepSanitize(Throwable t) {
    Throwable current = t;
    while (current.getCause() != null) {
        current = sanitize(current.getCause());
    }
    return sanitize(t);
}

From source file:org.jahia.services.usermanager.ldap.LdapProviderConfiguration.java

private static Exception getRootCause(Exception e) {
    Throwable cause = null;/*from   w w w.java2  s.  co m*/
    if (e instanceof NestedCheckedException) {
        cause = ((NestedCheckedException) e).getMostSpecificCause();
    } else if (e instanceof NestedRuntimeException) {
        cause = ((NestedRuntimeException) e).getMostSpecificCause();
    } else {
        Throwable t = e;
        while (t.getCause() != null) {
            t = t.getCause();
        }
        cause = t;
    }
    return (cause instanceof Exception) ? (Exception) cause : new RuntimeException(cause);
}

From source file:com.alibaba.wasp.client.ServerCallable.java

private static Throwable translateException(Throwable t) throws IOException {
    if (t instanceof UndeclaredThrowableException) {
        t = t.getCause();
    }//from w  w  w.  j av  a  2  s  . c  o m
    if (t instanceof RemoteException) {
        t = ((RemoteException) t).unwrapRemoteException();
    }
    if (t instanceof DoNotRetryIOException) {
        throw (DoNotRetryIOException) t;
    }
    if (t instanceof IOException) {
        RuntimeException runtimeException = unwrapRuntimeException(t);
        if (runtimeException != null) {
            return runtimeException;
        }
    }
    return t;
}

From source file:eu.delving.sip.Harvester.java

static String exceptionToErrorString(Exception exception) {
    StringBuilder out = new StringBuilder();
    out.append(exception.getMessage());//from w  w w .j av  a  2s.  c o m
    Throwable cause = exception.getCause();
    while (cause != null) {
        out.append('\n');
        out.append(cause.toString());
        cause = cause.getCause();
    }
    return out.toString();
}

From source file:org.overlord.sramp.server.servlets.MavenRepositoryServlet.java

/**
 * Gets the root exception from the given {@link Throwable}.
 *
 * @param t/*from w w  w. j av  a 2 s .c  om*/
 *            the t
 * @return the root cause
 */
public static Throwable getRootCause(Throwable t) {
    Throwable root = t;
    while (root.getCause() != null && root.getCause() != root)
        root = root.getCause();
    return root;
}

From source file:net.fenyo.gnetwatch.GenericTools.java

/**
 * Returns the full stack trace.//from   w  w  w .ja  v a 2s  . c  om
 * This function is a replacement to Throwable.getStackTrace() that writes "... XX [lines] more"
 * when there are too many entries in the stack trace.
 * @param ex exception.
 * @return String exception description with full stack trace.
 */
static public String getFullExceptionStackTrace(final Throwable ex) {
    String result = "";

    for (final StackTraceElement st : ex.getStackTrace())
        result += st.toString();

    if (ex.getCause() != null) {
        result += "caused by\n";
        for (final StackTraceElement st : ex.getCause().getStackTrace())
            result += st.toString();
    }

    return result;
}