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:jp.primecloud.auto.ui.ErrorHandler.java

/**
 * {@inheritDoc}/*from   ww  w . j a  v  a  2s .  c  o m*/
 */
@Override
public void terminalError(ErrorEvent event) {
    // ?
    Throwable throwable = event.getThrowable();
    if (throwable instanceof ListenerMethod.MethodException) {
        throwable = throwable.getCause();
    }

    // ??????
    if (!(throwable instanceof AutoException) && !(throwable instanceof MultiCauseException)) {
        String message = "[ECOMMON-000000] " + MessageUtils.getMessage("ECOMMON-000000");
        log.error(message, throwable);
    }

    String message;
    if (throwable instanceof AutoApplicationException) {
        // ?
        AutoApplicationException e = (AutoApplicationException) throwable;
        message = ViewMessages.getMessage(e.getCode(), e.getAdditions());
    } else {
        // ?????
        String code;
        if (throwable instanceof AutoException) {
            code = ((AutoException) throwable).getCode();
        } else {
            code = "ECOMMON-000000";
        }
        message = ViewMessages.getMessage("EUI-000001", code);
    }
    String caption = ViewProperties.getCaption("dialog.error");

    DialogConfirm dialog = new DialogConfirm(caption, message, Buttons.OK);
    mainWindow.addWindow(dialog);
}

From source file:br.ufac.sion.inscricao.util.jsf.JsfExceptionHandler.java

private NegocioException getNegocioException(Throwable exception) {
    if (exception instanceof NegocioException) {
        return (NegocioException) exception;
    } else if (exception.getCause() != null) {
        return getNegocioException(exception.getCause());
    }/*from  ww w  .  j  a  va2s  . c o m*/

    return null;
}

From source file:de.huxhorn.lilith.Lilith.java

@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored" })
private static void appendStatus(StringBuilder builder, Status status, int indent) {
    int levelCode = status.getLevel();
    appendIndent(builder, indent);//from  w w  w  .j a  v  a  2 s  . c  o  m
    if (levelCode >= 0 && levelCode < STATUS_TEXT.length) {
        builder.append(STATUS_TEXT[levelCode]);
    }
    builder.append(status.getMessage()).append('\n');
    Throwable t = status.getThrowable();
    while (t != null) {
        appendIndent(builder, indent + 1);
        builder.append(t.getClass().getName());
        String message = t.getMessage();
        if (message != null) {
            builder.append(": ").append(message);
        }
        builder.append('\n');
        // probably check for causes, too
        t = t.getCause();
    }
    if (status.hasChildren()) {
        Iterator<Status> children = status.iterator();
        while (children.hasNext()) {
            appendStatus(builder, children.next(), indent + 1);
        }
    }
}

From source file:net.sf.jabb.util.ex.LoggedException.java

/**
 * Create a new instance, and at the same time, ensure the original exception is logged.
 * //from   ww w .j  a v a2  s . co  m
 * @param log      the log utility
 * @param level      level of the log
 * @param message   description
 * @param cause      the original exception. If it is of type LoggedException, 
 *                then the newly created instance is a clone of itself.
 */
public LoggedException(Log log, int level, String message, Throwable cause) {
    super(cause instanceof LoggedException ? cause.getMessage() : message,
            cause instanceof LoggedException ? cause.getCause() : cause);
    if (!(cause instanceof LoggedException)) {
        switch (level) {
        case TRACE:
            if (log.isTraceEnabled()) {
                log.trace(message, cause);
            }
            break;
        case DEBUG:
            if (log.isDebugEnabled()) {
                log.debug(message, cause);
            }
            break;
        case WARN:
            if (log.isWarnEnabled()) {
                log.warn(message, cause);
            }
            break;
        case FATAL:
            log.fatal(message, cause);
            break;
        case INFO:
            log.info(message, cause);
            break;
        default:
            log.error(message, cause);
        }
    }
}

From source file:com.elasticbox.jenkins.k8s.repositories.error.RepositoryException.java

public String getCausedByMessages() {
    Throwable initialCause = getCause();
    if (initialCause != null) {
        StringBuilder msg = new StringBuilder();
        appendMessage(msg, initialCause);
        while (initialCause.getCause() != null) {
            initialCause = initialCause.getCause();
            appendMessage(msg, initialCause);
        }/*from   w w  w  . ja  v a  2  s .c  o  m*/
        return msg.toString();
    } else {
        return getMessage();
    }
}

From source file:com.haulmont.cuba.web.app.ui.jmxcontrol.inspect.operation.OperationResultWindow.java

protected String getExceptionMessage(Throwable exception) {
    if (exception instanceof UndeclaredThrowableException)
        exception = exception.getCause();

    if (exception instanceof JmxControlException) {
        exception = exception.getCause();

        if (exception instanceof MBeanException) {
            exception = exception.getCause();
        }/*from w ww  .j  a  v  a2  s  .c  o  m*/
    }

    String msg;
    if (exception != null) {
        msg = String.format("%s: \n%s\n%s", exception.getClass().getName(), exception.getMessage(),
                ExceptionUtils.getFullStackTrace(exception));
    } else {
        msg = "";
    }
    return msg;
}

From source file:com.sastix.cms.common.services.aop.MethodMonitor.java

@Around("execution(* com.sastix..services..*.*(..))")
public Object logServiceAccess(ProceedingJoinPoint joinPoint) throws Throwable {
    if (!LOG.isDebugEnabled()) {
        return joinPoint.proceed(); // if not on DEBUG, no point in writing anything
    }// www. j av  a  2  s .  c  o m

    String name = joinPoint.getSignature().getName();
    LOG.debug("==> {}({})", name, argsAsStrings(joinPoint.getArgs()));

    try {
        Object obj = joinPoint.proceed(); //continue on the intercepted method
        LOG.debug("<==  {}(...) = {}", name, argsAsStrings(obj));
        return obj;
    } catch (Throwable t) {
        LOG.error("<==! {}(...) => EXCEPTION {}", new Object[] { name, t.getMessage() });
        if (t.getCause() != null) {
            LOG.error("<==! caused by: {} - message: {}", t.getCause(), t.getCause().getMessage());
        }
        LOG.error("<==! exception log: ", t);
        throw t;
    }

}

From source file:es.pode.adminusuarios.negocio.servicios.AltaGrupoException.java

/**
 * Finds the root cause of the parent exception
 * by traveling up the exception tree/*www  .  j  a v  a 2s  . c  o m*/
 */
private static Throwable findRootCause(Throwable th) {
    if (th != null) {
        // Lets reflectively get any JMX or EJB exception causes.
        try {
            Throwable targetException = null;
            // java.lang.reflect.InvocationTargetException
            // or javax.management.ReflectionException
            String exceptionProperty = "targetException";
            if (PropertyUtils.isReadable(th, exceptionProperty)) {
                targetException = (Throwable) PropertyUtils.getProperty(th, exceptionProperty);
            } else {
                exceptionProperty = "causedByException";
                //javax.ejb.EJBException
                if (PropertyUtils.isReadable(th, exceptionProperty)) {
                    targetException = (Throwable) PropertyUtils.getProperty(th, exceptionProperty);
                }
            }
            if (targetException != null) {
                th = targetException;
            }
        } catch (Exception ex) {
            // just print the exception and continue
            ex.printStackTrace();
        }

        if (th.getCause() != null) {
            th = th.getCause();
            th = findRootCause(th);
        }
    }
    return th;
}

From source file:com.wiiyaya.consumer.web.main.controller.ExceptionController.java

private Throwable getRootCause(Throwable exception) {
    if (exception.getCause() != null) {
        return getRootCause(exception.getCause());
    }//w  ww. ja v  a2 s. co m
    return exception;
}

From source file:com.cloud.utils.log.CglibThrowableRenderer.java

@Override
public String[] doRender(Throwable th) {
    List<String> lines = new ArrayList<String>();
    lines.add(th.toString());/*w ww .j a  va 2 s . c  o m*/
    addStackTraceToList(th, lines, 0);
    do {
        th = th.getCause();
        if (th != null) {
            lines.add("Caused by: " + th.toString());
            addStackTraceToList(th, lines, MAX_NUMBER_OF_STACK_TRACES_ON_LOG_FOR_CAUSE);
        }
    } while (th != null);
    return lines.toArray(new String[lines.size()]);
}