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:com.mycollab.configuration.logging.ExceptionFilter.java

private static boolean isInstanceInBlackList(Class cls, Throwable throwable) {
    return cls.isInstance(throwable)
            || throwable.getCause() != null && isInstanceInBlackList(cls, throwable.getCause());
}

From source file:adalid.commons.util.ThrowableUtils.java

public static Throwable getCause(Throwable throwable) {
    if (throwable == null) {
        return null;
    }/*from w w w . j a v  a  2 s.c  o  m*/
    Throwable cause = throwable.getCause();
    return cause == null ? throwable : getCause(cause);
}

From source file:com.norbl.util.StringUtil.java

public static String getExceptionMessage(Throwable x) {
    Throwable c = x.getCause();
    if ((c != null) && (c.getMessage() != null) && (c.getMessage().length() > 0)) {
        return (c.getMessage());
    } else//from   ww w  .  j a  v  a  2  s . c  om
        return (x.toString());
}

From source file:com.esofthead.mycollab.configuration.logging.ExceptionFilter.java

private static boolean isInstanceInBlackList(Class cls, Throwable throwable) {
    if (cls.isInstance(throwable)) {
        return true;
    }//www  .  j  av a 2  s .c  o  m
    if (throwable.getCause() != null) {
        return isInstanceInBlackList(cls, throwable.getCause());
    }
    return false;
}

From source file:com.hihframework.osplugins.json.JsonUtil.java

/**
 * ejson/*from   w ww.  j  a  va2 s . com*/
 * 
 * @param e
 * @return
 */
public synchronized static String toString(Throwable e) {
    Throwable now = e;
    Throwable next = now.getCause();
    while (next != null) {
        now = next;
        next = now.getCause();
    }
    Map<String, String> map = new HashMap<String, String>();
    map.put("error", now.toString());
    map.put("message", now.getMessage() == null ? "" : now.getMessage());
    return JSONObject.fromObject(map).toString();
}

From source file:org.red5.server.Standalone.java

/**
  * Re-throws exception/*from   ww w .  ja  va2s . c om*/
  * @param e               Exception
  * @throws Throwable      Re-thrown exception
  */
public static void raiseOriginalException(Throwable e) throws Throwable {
    // Search for root exception
    while (e.getCause() != null) {
        e = e.getCause();
    }
    throw e;
}

From source file:co.marcin.novaguilds.util.LoggerUtils.java

public static void exception(Throwable e) {
    Throwable cause = e.getCause();
    error("", false);
    error("[NovaGuilds] Severe error: " + e.getClass().getSimpleName(), false);
    error("", false);
    error("Server Information:", false);
    error("  NovaGuilds: #" + VersionUtils.getBuildCurrent() + " (" + VersionUtils.getCommit() + ")", false);
    error("  Storage Type: "
            + (plugin.getConfigManager() == null || plugin.getConfigManager().getDataStorageType() == null
                    ? "null"
                    : plugin.getConfigManager().getDataStorageType().name()),
            false);//from   ww  w .  j a  va  2  s.  c  o  m
    error("  Bukkit: " + Bukkit.getBukkitVersion(), false);
    error("  Java: " + System.getProperty("java.version"), false);
    error("  Thread: " + Thread.currentThread(), false);
    error("  Running CraftBukkit: "
            + Bukkit.getServer().getClass().getName().equals("org.bukkit.craftbukkit.CraftServer"), false);
    error("  Exception Message: ", false);
    error("   " + e.getMessage(), false);
    error("", false);

    error("Stack trace: ", false);
    printStackTrace(e.getStackTrace());
    error("", false);

    while (cause != null) {
        error("Caused by: " + cause.getClass().getName(), false);
        error("  " + cause.getMessage(), false);

        printStackTrace(cause.getStackTrace());
        error("", false);
        cause = cause.getCause();
    }

    error("End of Error.", false);
    error("", false);

    //notify all permitted players
    Message.CHAT_ERROROCCURED.broadcast(Permission.NOVAGUILDS_ERROR);
}

From source file:com.redhat.lightblue.util.metrics.DropwizardRequestMetrics.java

/**
 * Get to the cause we actually care about in case the bubbled up exception is a
 * higher level framework exception that encapsulates the stuff we really care
 * about.//w w  w. j  a  va2 s.c  o  m
 * 
 */
private static Class<? extends Throwable> unravelReflectionExceptions(Throwable e) {
    while (e.getCause() != null
            && (e instanceof UndeclaredThrowableException || e instanceof InvocationTargetException)) {
        e = e.getCause();
    }
    return e.getClass();
}

From source file:Main.java

public static String getStackTraceString(Throwable tr) {
    if (tr == null) {
        return "";
    }/*  www.j  ava2  s.c om*/

    // This is to reduce the amount of log spew that apps do in the non-error
    // condition of the network being unavailable.
    Throwable t = tr;
    while (t != null) {
        if (t instanceof UnknownHostException) {
            return "";
        }
        t = t.getCause();
    }

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    tr.printStackTrace(pw);
    pw.flush();
    return sw.toString();
}

From source file:ch.cern.dss.teamcity.server.AsyncTagRequestController.java

/**
 * @param e/*from  w w w  .  j  a va  2  s .  c o  m*/
 *
 * @return
 */
static private String getMessageWithNested(Throwable e) {
    String result = e.getMessage();
    Throwable cause = e.getCause();
    if (cause != null) {
        result += " Caused by: " + getMessageWithNested(cause);
    }
    return result;
}