Example usage for java.lang RuntimeException getCause

List of usage examples for java.lang RuntimeException getCause

Introduction

In this page you can find the example usage for java.lang RuntimeException 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:co.paralleluniverse.fibers.okhttp.FiberOkHttpUtils.java

private static <X> X fiberOkTry(final SuspendableCallable<X> call)
        throws InterruptedException, IOException, ExecutionException {
    X res = null;/*from w  w  w . j  a v  a 2s  . co m*/
    try {
        res = new Fiber<>(call).start().get();
    } catch (ExecutionException ee) {
        if (ee.getCause() instanceof RuntimeException) {
            final RuntimeException re = (RuntimeException) ee.getCause();
            if (re.getCause() instanceof IOException)
                throw (IOException) re.getCause();
            else
                throw re;
        } else if (ee.getCause() instanceof IllegalStateException)
            throw ((IllegalStateException) ee.getCause());
        else
            throw ee;
    }
    // Should never happen
    return res;
}

From source file:com.sample.common.util.AssertUtil.java

public static void assertNotNull(Object object, RuntimeException cause) {
    if (object == null) {
        cause.initCause(cause.getCause());
        throw cause;
    }//from   w w  w  .  j  a  v  a 2s.  c  o  m
}

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

/**
 * Given a RuntimeException, this method will:
 * - throw its cause exception, if the cause exception is an instance of the type of the unwrapIf parameter
 * - throw its cause exception, if the cause exception is a RuntimeException
 * - throw the given RuntimeException otherwise.
 *///from   w  w w.j  ava2 s .  c o m
public static <E extends Throwable> void unwrapIf(RuntimeException e, Class<E> unwrapIf) throws E {
    final Throwable wrapped = e.getCause();
    if (unwrapIf != null && unwrapIf.isInstance(wrapped)) {
        throw (E) wrapped;
    } else if (wrapped != null && wrapped instanceof RuntimeException) {
        throw (RuntimeException) wrapped;
    } else {
        throw e;
    }
}

From source file:com.auditbucket.helper.DeadlockRetry.java

public static Command execute(Command command, String block, int maxRetry) throws DatagioException {
    // Deadlock re-try fun
    int retryCount = 0;
    while (retryCount < maxRetry) {
        try {/*w  w w  . ja  v a2  s . co m*/
            return command.execute();
        } catch (RuntimeException re) {
            // ToDo: Exceptions getting wrapped in a JedisException. Can't directly catch the DDE hence the instanceof check
            if (re.getCause() instanceof NotFoundException || re.getCause() instanceof DeadlockDetectedException
                    || re.getCause() instanceof InvalidDataAccessResourceUsageException
                    || re.getCause() instanceof DataRetrievalFailureException) {
                logger.debug("Deadlock Detected. Entering retry [{}]", block);
                Thread.yield();
                retryCount++;
                if (retryCount == maxRetry) {
                    // http://www.slideshare.net/neo4j/zephyr-neo4jgraphconnect-2013short
                    logger.error("Deadlock retries exceeded in [{}]", block);
                    throw (re);
                }
            } else {
                logger.error("DeadlockRetry error could not be handled {}", re.getMessage());
                throw (re);
            }
        }
    }
    return null;
}

From source file:devfigas.com.neverlargeexception.IntentTransporter.java

public static void startActivity(Fragment from, SuperIntent superIntent, RuntimeException runtimeException) {
    if (runtimeException == null || runtimeException.getCause() instanceof TransactionTooLargeException) {
        sSuperIntent = SuperIntent.receive(superIntent, from);
    }//from  w  w w  .  ja  v a2  s  .c  om
}

From source file:devfigas.com.neverlargeexception.IntentTransporter.java

public static void startActivity(AppCompatActivity from, SuperIntent superIntent,
        RuntimeException runtimeException) {
    if (runtimeException == null || runtimeException.getCause() instanceof TransactionTooLargeException) {
        sSuperIntent = SuperIntent.receive(superIntent, from);
    }/*  w w  w.  j a va2 s .  c  o  m*/
}

From source file:devfigas.com.neverlargeexception.IntentTransporter.java

public static void startActivityForResult(AppCompatActivity from, SuperIntent superIntent,
        RuntimeException runtimeException, int requestCode) {
    if (runtimeException == null || runtimeException.getCause() instanceof TransactionTooLargeException) {
        sSuperIntent = SuperIntent.receiveForResult(superIntent, from, requestCode);
    }/*from   w w  w  .j a  v a 2s .c om*/
}

From source file:devfigas.com.neverlargeexception.IntentTransporter.java

public static void startActivityForResult(Fragment from, SuperIntent superIntent,
        RuntimeException runtimeException, int requestCode) {
    if (runtimeException == null || runtimeException.getCause() instanceof TransactionTooLargeException) {
        sSuperIntent = SuperIntent.receiveForResult(superIntent, from, requestCode);
    }/*from w  w  w.  j a v  a 2 s.  co m*/
}

From source file:org.apache.hadoop.fs.s3a.S3AUtils.java

/**
 * Create the AWS credentials from the providers and the URI.
 * @param binding Binding URI, may contain user:pass login details
 * @param conf filesystem configuration//from  w ww. j  av  a2 s.c om
 * @param fsURI fS URI after any login details have been stripped.
 * @return a credentials provider list
 * @throws IOException Problems loading the providers (including reading
 * secrets from credential files).
 */
public static AWSCredentialProviderList createAWSCredentialProviderSet(URI binding, Configuration conf,
        URI fsURI) throws IOException {
    AWSCredentialProviderList credentials = new AWSCredentialProviderList();

    Class<?>[] awsClasses;
    try {
        awsClasses = conf.getClasses(AWS_CREDENTIALS_PROVIDER);
    } catch (RuntimeException e) {
        Throwable c = e.getCause() != null ? e.getCause() : e;
        throw new IOException("From option " + AWS_CREDENTIALS_PROVIDER + ' ' + c, c);
    }
    if (awsClasses.length == 0) {
        S3xLoginHelper.Login creds = getAWSAccessKeys(binding, conf);
        credentials.add(new BasicAWSCredentialsProvider(creds.getUser(), creds.getPassword()));
        credentials.add(new EnvironmentVariableCredentialsProvider());
        credentials.add(new InstanceProfileCredentialsProvider());
    } else {
        for (Class<?> aClass : awsClasses) {
            credentials.add(createAWSCredentialProvider(conf, aClass, fsURI));
        }
    }
    return credentials;
}

From source file:org.springmodules.workflow.jbpm30.JbpmSessionFactoryUtils.java

/**
 * Converts Jbpm RuntimeExceptions into Spring specific ones (if possible).
 * @param ex//  ww w. ja va2s . c  o  m
 * @return
 */
public static RuntimeException convertJbpmException(RuntimeException ex) {
    // try to decode and translate HibernateExceptions
    if (ex instanceof HibernateException) {
        return SessionFactoryUtils.convertHibernateAccessException((HibernateException) ex);
    }

    if (ex.getCause() instanceof HibernateException) {
        DataAccessException rootCause = SessionFactoryUtils
                .convertHibernateAccessException((HibernateException) ex.getCause());
        return new NestedDataAccessException(ex.getMessage(), rootCause);
    }

    // cannot convert the exception in any meaningful way
    return ex;
}