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.shigengyu.hyperion.core.WorkflowTransition.java

public WorkflowStateSet invoke(WorkflowInstance workflowInstance) {
    try {/* ww  w . j  ava  2  s .com*/
        if (method.getParameterTypes().length == 0) {
            return (WorkflowStateSet) method.invoke(workflowInstance.getWorkflowDefinition());
        } else if (method.getParameterTypes().length == 1
                && method.getParameterTypes()[0] == WorkflowInstance.class) {
            return (WorkflowStateSet) method.invoke(workflowInstance.getWorkflowDefinition(), workflowInstance);
        } else {
            throw new WorkflowExecutionException(
                    "Workflow transition must take one parameter of type WorkflowInstance or no parameters");
        }
    } catch (InvocationTargetException e) {
        Throwable t = e;
        do {
            t = t.getCause();
        } while (t instanceof InvocationTargetException);

        throw new TransitionInvocationException(t);
    } catch (Exception e) {
        throw new WorkflowExecutionException(e);
    }
}

From source file:org.obiba.mica.core.LoggingAspect.java

@AfterThrowing(pointcut = WITHIN_EXPR, throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
    if (env.acceptsProfiles(Profiles.DEV)) {
        logger.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), e.getCause(), e);
    } else {/*from w w w  . ja  va  2s.c  o m*/
        logger.error("Exception in {}.{}() with cause = {}", joinPoint.getSignature().getDeclaringTypeName(),
                joinPoint.getSignature().getName(), e.getCause());
    }
}

From source file:com.hortonworks.hbase.replication.bridge.ReplicationBridgeServer.java

public boolean checkOOME(final Throwable e) {
    boolean stop = false;
    try {//from   ww  w  .  j  a  v  a 2  s  .  c om
        if (e instanceof OutOfMemoryError || (e.getCause() != null && e.getCause() instanceof OutOfMemoryError)
                || (e.getMessage() != null && e.getMessage().contains("java.lang.OutOfMemoryError"))) {
            stop = true;
            LOG.fatal("Run out of memory; HRegionServer will abort itself immediately", e);
        }
    } finally {
        if (stop) {
            Runtime.getRuntime().halt(1);
        }
    }
    return stop;
}

From source file:org.fornax.cartridges.sculptor.framework.web.errorhandling.ExceptionAdvice.java

protected String handleWrappingException(RequestContext requestContext, RuntimeException e) {
    Throwable cause = (e.getCause() == null ? e : e.getCause());
    if (cause instanceof RemoteException) {
        cause = cause.getCause();
    }//from www . j  a va 2s.co  m
    OptimisticLockingException ole = unwrapOptimisticLockingException(cause);
    ValidationException idoe = unwrapValidationException(cause);
    if (ole != null) {
        return handleOptimisticLockingException(requestContext, ole);
    } else if (idoe != null) {
        return handleValidationException(requestContext, idoe);
    } else if (cause instanceof RuntimeException) {
        throw (RuntimeException) cause;
    } else {
        // not a wrapped exception
        throw e;
    }
}

From source file:cn.newgxu.lab.core.controller.GlobalExceptionHandler.java

/**
 * ??ajaxhtml~// ww  w  .  j  a  va 2  s  .c  o m
 * @param t ?
 * @return json or html depends on what the client wants!
 */
@ExceptionHandler(Throwable.class)
public ModelAndView exp(Throwable t) {
    L.error("?", t);
    ModelAndView mav = new ModelAndView(ERROR_PAGE);
    mav.addObject(AJAX_STATUS, "no");
    mav.addObject(AJAX_MESSAGE, t.getMessage());
    if (t.getCause() != null) {
        mav.addObject(EXP_REASON, t.getCause().getMessage());
    } else {
        mav.addObject(EXP_REASON, UNKNOWN_REASON);
    }
    return mav;
}

From source file:org.thingsplode.server.bus.executors.AbstractExecutor.java

protected String determineExceptionMessage(Throwable e) {
    if (e == null) {
        return null;
    }//ww w.j ava2 s. c o m
    if (e.getMessage() != null && !e.getMessage().isEmpty()) {
        return e.getMessage();
    } else {
        return determineExceptionMessage(e.getCause());
    }

}

From source file:com.netflix.hystrix.contrib.javanica.command.BatchHystrixCommand.java

@Override
@SuppressWarnings("unchecked")
protected List<Object> getFallback() {
    if (getFallbackAction() != null) {
        final CommandAction commandAction = getFallbackAction();

        try {/*from w  w w .  ja v  a 2 s.co m*/
            return (List<Object>) process(new Action() {
                @Override
                Object execute() {
                    Object[] args = toArgs(getCollapsedRequests());
                    if (commandAction.getMetaHolder().isExtendedFallback()) {
                        if (commandAction.getMetaHolder().isExtendedParentFallback()) {
                            args[args.length - 1] = getFailedExecutionException();
                        } else {
                            args = Arrays.copyOf(args, args.length + 1);
                            args[args.length - 1] = getFailedExecutionException();
                        }
                    } else {
                        if (commandAction.getMetaHolder().isExtendedParentFallback()) {
                            args = ArrayUtils.remove(args, args.length - 1);
                        }
                    }
                    return commandAction
                            .executeWithArgs(commandAction.getMetaHolder().getFallbackExecutionType(), args);
                }
            });
        } catch (Throwable e) {
            LOGGER.error(FallbackErrorMessageBuilder.create().append(commandAction, e).build());
            throw new FallbackInvocationException(e.getCause());
        }
    } else {
        return super.getFallback();
    }

}

From source file:org.fornax.cartridges.sculptor.framework.drools.DroolsAdvice.java

public Object invoke(MethodInvocation procJointpoint) throws Throwable {
    long startTimeExec = System.currentTimeMillis();
    log.info("############# START DROOLS RULES");
    RequestDescription req = new RequestDescription(procJointpoint);
    try {/*w ww. ja va2 s  .  com*/
        Object[] arguments = procJointpoint.getArguments();
        ServiceContext ctx;
        int startArg;
        if (arguments[0] instanceof ServiceContext) {
            ctx = (ServiceContext) arguments[0];
            startArg = 1;
        } else {
            ctx = ServiceContextStore.get();
            startArg = 0;
        }

        HashMap<String, Object> objects = new HashMap<String, Object>();
        for (int i = startArg; i < arguments.length; i++) {
            objects.put("arg" + i, arguments[i]);
        }
        objects.put("request", req);
        objects.put("service", procJointpoint.getThis());
        objects.put("username", ServiceContextStore.getCurrentUser());

        HashMap<String, Object> globals = new HashMap<String, Object>();
        if (ctx != null) {
            globals.put("serviceContext", ctx);
        }
        globals.put("appContext", appContext);
        globals.put("log", log);

        Calendar curDate = Calendar.getInstance();
        globals.put("currentDate", curDate);
        globals.put("currentTimestamp", curDate.getTimeInMillis());

        applyCompanyPolicy(objects, globals);
    } catch (Throwable th) {
        if (catchAllExceptions) {
            while (th.getCause() != null) {
                th = th.getCause();
            }
            log.warn("Applying company policy finished with error: " + th.getMessage(), th);
        } else {
            throw th;
        }
    } finally {
        log.info("############# END DROOLS RULES (" + (System.currentTimeMillis() - startTimeExec) + " ms)");
    }

    if (req.wasProceed() && req.getLastResult() != null && req.getLastResult() instanceof Throwable) {
        throw (Throwable) req.getLastResult();
    } else if (req.wasProceed()) {
        return req.getLastResult();
    } else {
        return procJointpoint.proceed();
    }
}

From source file:org.trustedanalytics.examples.hbase.api.ExceptionHandlerAdvice.java

private HttpStatus resolveAnnotatedResponseStatus(Throwable ex) {
    ResponseStatus responseStatus = findMergedAnnotation(ex.getClass(), ResponseStatus.class);
    if (responseStatus != null) {
        return responseStatus.code();
    } else if (ex.getCause() instanceof Exception) {
        return resolveAnnotatedResponseStatus(ex.getCause());
    }// w w w  .  ja  v  a2  s .  com
    return null;
}

From source file:io.orchestrate.client.integration.FetchTest.java

@Test
public void fetchObjectCantDeserialize() throws InterruptedException, ExecutionException, TimeoutException {
    final String key = generateString();
    final String value = "{\"some_field\": \"Hello World!\"}";

    KvStoreOperation kvStoreOp = new KvStoreOperation(TEST_COLLECTION, key, value);
    Future<KvMetadata> future_1 = client().execute(kvStoreOp);
    KvMetadata kvMetadata = future_1.get(3, TimeUnit.SECONDS);

    KvFetchOperation<MyObject> kvFetchOp = new KvFetchOperation<MyObject>(TEST_COLLECTION, key, MyObject.class);

    try {/*ww  w .  j  a  v  a2 s .  c  om*/
        KvObject<MyObject> result = result(kvFetchOp);
    } catch (final Throwable t) {
        assertThat(t.getCause(), instanceOf(UnrecognizedPropertyException.class));
    }
}