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:edu.uci.ics.asterix.result.ResultUtils.java

private static Throwable getRootCause(Throwable cause) {
    Throwable nextCause = cause.getCause();
    while (nextCause != null) {
        cause = nextCause;/*from   w  w  w. j  av a2 s  .c  o  m*/
        nextCause = cause.getCause();
    }
    return cause;
}

From source file:cc.sion.core.utils.Exceptions.java

/**
 * ??????, ?/*from  www. j  a va 2 s  . c o m*/
 */
public static String getErrorMessageWithNestedException(Throwable ex) {
    Throwable nestedException = ex.getCause();
    return new StringBuilder().append(ex.getMessage()).append(" nested exception is ")
            .append(nestedException.getClass().getName()).append(":").append(nestedException.getMessage())
            .toString();
}

From source file:info.magnolia.cms.util.ExceptionUtil.java

/**
 * Returns true if the given exception or any of the nested cause exceptions is an instance of the <tt>suspectedCause</tt> exception argument, or a subclass thereof.
 * This is equivalent to ExceptionUtils.indexOfThrowable(e, javax.jcr.AccessDeniedException.class) >= 0, only more readable, and possibly more performant.
 *//*from ww w .j  av a2 s .c  om*/
public static boolean wasCausedBy(Throwable e, Class<? extends Throwable> suspectedCause) {
    if (e != null && suspectedCause.isAssignableFrom(e.getClass())) {
        return true;
    } else if (e == null) {
        return false;
    } else {
        return wasCausedBy(e.getCause(), suspectedCause);
    }
}

From source file:com.wavemaker.common.util.SystemUtils.java

/**
 * Remove all wrapping Exceptions that have been "artificially" added to the top-level root Exception.
 *///  www  . java 2s .c  o m
public static Throwable unwrapInternalException(Throwable th) {

    while (th instanceof WMRuntimeException || th instanceof WMException) {

        if (th.getCause() != null) {
            th = th.getCause();
        } else {
            break;
        }
    }

    return th;
}

From source file:com.squarespace.gibson.GibsonUtils.java

private static void append(MessageDigest md, Throwable throwable) {
    if (throwable != null) {
        append(md, throwable.getClass());
        append(md, getStackTrace(throwable));

        Throwable cause = throwable.getCause();
        if (cause != null && cause != throwable) {
            append(md, cause);/*  w  ww  .  j  a v  a  2s  .com*/
        }
    }
}

From source file:com.github.ibole.infrastructure.common.exception.MoreThrowables.java

/**
 * ??./*from  w  ww.j  ava2 s .  c  o  m*/
 */
@SuppressWarnings("unchecked")
public static boolean isCausedBy(Exception ex, Class<? extends Exception>... causeExceptionClasses) {
    Throwable cause = ex.getCause();
    while (cause != null) {
        for (Class<? extends Exception> causeClass : causeExceptionClasses) {
            if (causeClass.isInstance(cause)) {
                return true;
            }
        }
        cause = cause.getCause();
    }
    return false;
}

From source file:com.googlecode.dex2jar.v3.Main.java

public static void niceExceptionMessage(Throwable t, int deep) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < deep + 1; i++) {
        sb.append(".");
    }//from w  w w  . ja va  2  s .  c  om
    sb.append(' ');
    if (t instanceof DexException) {
        sb.append(t.getMessage());
        System.err.println(sb.toString());
        if (t.getCause() != null) {
            niceExceptionMessage(t.getCause(), deep + 1);
        }
    } else {
        if (t != null) {
            System.err.println(sb.append("ROOT cause:").toString());
            t.printStackTrace(System.err);
        }
    }
}

From source file:com.aw.support.reflection.MethodInvoker.java

public static Object invoke(Object target, String methodName, Object[] parameters) throws Throwable {
    Object result = null;//from w  w w.  j a v a 2 s.c o  m
    try {
        Class cls = target.getClass();
        Class[] paramTypes = new Class[parameters.length];
        for (int i = 0; i < paramTypes.length; i++) {
            paramTypes[i] = parameters[i].getClass();
        }
        Method method = cls.getMethod(methodName, paramTypes);
        method.setAccessible(true);
        result = method.invoke(target, parameters);
    } catch (Throwable e) {
        if (e.getCause() instanceof AWException) {
            throw ((AWException) e.getCause());
        }
        e.printStackTrace();
        throw e;
    }
    return result;
}

From source file:com.metadave.kash.KashConsole.java

private static void processOutput(KashRuntimeContext runtimeCtx, PrintWriter out, boolean ansi) {
    List<Throwable> errors = runtimeCtx.getErrors();
    for (Throwable t : errors) {

        ANSIBuffer buf = new ANSIBuffer();
        buf.setAnsiEnabled(ansi);/*from  www .  j a  v  a 2 s .com*/
        buf.red(t.getMessage());
        if (t.getCause() != null) {
            buf.red(":" + t.getCause().getMessage());
        }
        buf.append("\n");
        System.out.print(buf.toString());
    }
    // TODO
    //runtimeCtx.reset();
}

From source file:com.machinepublishers.jbrowserdriver.Util.java

static void handleException(Throwable throwable) {
    if (throwable != null) {
        String message = throwable.getMessage();
        if ((throwable instanceof UncheckedExecutionException || throwable instanceof RemoteException)
                && throwable.getCause() != null) {
            throwable = throwable.getCause();
            message = throwable.getMessage();
        }/*from  w w  w  . ja v  a  2 s  .  c om*/
        if (throwable instanceof WebDriverException && throwable instanceof RuntimeException) {
            //Wrap the exception to ensure complete/helpful stack trace info and also preserve the original subtype
            try {
                throwable = throwable.getClass().getConstructor(String.class, Throwable.class)
                        .newInstance(message, throwable);
            } catch (Throwable t) {
                try {
                    throwable = throwable.getClass().getConstructor(Throwable.class).newInstance(throwable);
                } catch (Throwable t2) {
                }
            }
            throw (RuntimeException) throwable;
        }
        throw new WebDriverException(message, throwable);
    }
}