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.cubeia.backoffice.web.BackofficeRequestCycleListener.java

private void fillInCausesRecursive(List<Throwable> causes, Throwable e) {
    if (e != null) {
        causes.add(e);/*from w  ww  . j  a v a  2 s.  c  o m*/
        fillInCausesRecursive(causes, e.getCause());
    }
}

From source file:com.bstek.dorado.web.resolver.ErrorPageResolver.java

private void doExcecute(HttpServletRequest request, HttpServletResponse response)
        throws Exception, IOException {
    response.setContentType(HttpConstants.CONTENT_TYPE_HTML);
    response.setCharacterEncoding(Constants.DEFAULT_CHARSET);

    Context velocityContext = new VelocityContext();
    Exception e = (Exception) request.getAttribute(EXCEPTION_ATTRIBUTE);
    if (e != null) {
        logger.error(e, e);/*from  w  w  w.j  a  v  a 2s  . c  o m*/

        if (e instanceof PageNotFoundException) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        } else if (e instanceof PageAccessDeniedException) {
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        }

        Throwable throwable = e;
        while (throwable.getCause() != null) {
            throwable = throwable.getCause();
        }

        String message = null;
        if (throwable != null) {
            message = throwable.getMessage();
        }
        message = StringUtils.defaultString(message, throwable.getClass().getName());

        velocityContext.put("message", message);
        velocityContext.put(EXCEPTION_ATTRIBUTE, throwable);
    } else {
        velocityContext.put("message", "Can not gain exception information!");
    }
    velocityContext.put("esc", stringEscapeHelper);

    Template template = getVelocityEngine().getTemplate("com/bstek/dorado/web/resolver/ErrorPage.html");

    PrintWriter writer = getWriter(request, response);
    try {
        template.merge(velocityContext, writer);
    } finally {
        writer.flush();
        writer.close();
    }
}

From source file:it.tidalwave.northernwind.frontend.util.InitializationDiagnosticsDispatcherServletDecorator.java

/*******************************************************************************************************************
 *
 *
 ******************************************************************************************************************/
@Nonnull// www .j  a  v a 2 s  . c  o  m
private Throwable findUpperCauseWithMessage(final @Nonnull Throwable throwable) {
    Throwable cause = throwable;

    for (Throwable parent = cause.getCause(); parent != null; parent = parent.getCause()) {
        final String message = parent.getMessage();

        if ((message != null) && !"".equals(message.trim())) {
            cause = parent;
        }
    }

    return cause;
}

From source file:de.hsos.ecs.richwps.wpsmonitor.boundary.cli.MonitorCli.java

private void appendExceptionMessages(final StringBuilder strBuilder, final Throwable ex) {
    strBuilder.append(ex.getMessage());/* ww w . j  av a 2  s .  c  o m*/

    if (ex.getCause() != null) {
        strBuilder.append(" ");
        appendExceptionMessages(strBuilder, ex.getCause());
    }
}

From source file:cc.kune.core.server.rack.filters.gwts.DelegatedRemoteServlet.java

@Override
protected void doUnexpectedFailure(final Throwable except) {
    final Throwable cause = except.getCause();
    LOG.info("Exception " + except.getMessage() + cause != null ? " cause: " + cause : "");
    super.doUnexpectedFailure(except);
}

From source file:io.dropwizard.primer.PerimerAuthorizationsTest.java

private boolean validateException(Throwable e) {
    boolean exception = e instanceof PrimerException;
    if (e.getCause() instanceof PrimerException) {
        exception = true;/*from  w  w w  .  jav a  2s. c om*/
    } else if (e.getCause() instanceof CompletionException) {
        if (e.getCause().getCause() instanceof PrimerException) {
            exception = true;
        }
    }
    return exception;
}

From source file:com.igormaznitsa.jcp.expression.functions.AbstractFunctionTest.java

protected Throwable getRootCause(final Throwable thr) {
    if (thr == null)
        return null;
    Throwable t = thr;
    while (t != null) {
        if (t.getCause() == null)
            return t;
        t = t.getCause();/*from w w  w  . ja  v  a 2s .  c o  m*/
    }
    return t;
}

From source file:com.juick.android.Utils.java

public static Throwable getRootException(Throwable e, int maxLoop) {
    if (e.getCause() == e)
        return e;
    if (e.getCause() == null)
        return e;
    if (maxLoop == 0)
        return e;
    return getRootException(e.getCause(), maxLoop - 1);

}

From source file:me.j360.boot.standard.test.SessionRedisApplicationTests.java

private boolean redisServerRunning(Throwable ex) {
    if (ex instanceof RedisConnectionFailureException) {
        return false;
    }/*from   ww  w  .  j a v  a2  s  . c  om*/
    return (ex.getCause() == null || redisServerRunning(ex.getCause()));
}

From source file:com.atinternet.tracker.CrashDetectionHandler.java

@Override
public void uncaughtException(Thread thread, Throwable throwable) {
    String className = (throwable.getCause() != null) ? getClassNameException(throwable.getCause())
            : getClassNameException(throwable);
    String exceptionName = (throwable.getCause() != null) ? throwable.getCause().getClass().getName()
            : throwable.getClass().getName();

    preferences.edit().putBoolean(CRASH_DETECTION, true)
            .putString(CRASH_LAST_SCREEN, lastScreen != null ? lastScreen : "")
            .putString(CRASH_CLASS_CAUSE, className)
            .putString(CRASH_EXCEPTION_NAME, exceptionName != null ? exceptionName : "").apply();
    defaultHandler.uncaughtException(thread, throwable);
}