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:uk.codingbadgers.SurvivalPlus.error.ReportExceptionRunnable.java

private String getException(Throwable cause) {
    while (cause.getCause() != null) {
        cause = cause.getCause();/* w w w . java  2 s  .  co  m*/
    }

    return cause.getClass().getName();
}

From source file:uk.codingbadgers.SurvivalPlus.error.ReportExceptionRunnable.java

private String getMessage(Throwable cause) {
    while (cause.getCause() != null) {
        cause = cause.getCause();//w  w w  . j a v  a2  s . co  m
    }

    return cause.getMessage();
}

From source file:com.alibaba.wasp.EntityGroupMovedException.java

/**
 * Look for a EntityGroupMovedException in the exception: - hadoop.ipc wrapped
 * exceptions - nested exceptions Returns null if we didn't find the exception
 * or if it was not readable./*w ww. j av a  2s . c  om*/
 */
public static EntityGroupMovedException find(Object exception) {
    if (exception == null || !(exception instanceof Throwable)) {
        return null;
    }

    Throwable cur = (Throwable) exception;
    EntityGroupMovedException res = null;

    while (res == null && cur != null) {
        if (cur instanceof EntityGroupMovedException) {
            res = (EntityGroupMovedException) cur;
        } else {
            if (cur instanceof RemoteException) {
                RemoteException re = (RemoteException) cur;
                Exception e = re.unwrapRemoteException(EntityGroupMovedException.class);
                if (e == null) {
                    e = re.unwrapRemoteException();
                }
                // unwrapRemoteException can return the exception given as a parameter
                // when it cannot
                // unwrap it. In this case, there is no need to look further
                // noinspection ObjectEquality
                if (e != re) {
                    res = find(e);
                }
            }
            cur = cur.getCause();
        }
    }

    if (res != null && (res.getPort() < 0 || res.getHostname() == null)) {
        // We failed to parse the exception. Let's act as we don't find the
        // exception.
        return null;
    } else {
        return res;
    }
}

From source file:org.apache.camel.component.dns.DNSLookupEndpointSpringTest.java

@Test
public void testDNSWithNoHeaders() throws Exception {
    _resultEndpoint.expectedMessageCount(0);
    try {/* ww  w  . j  ava2s.c  om*/
        _template.sendBody("hello");
    } catch (Throwable t) {
        assertTrue(t.getCause() instanceof IllegalArgumentException);
    }
    _resultEndpoint.assertIsSatisfied();
}

From source file:net.solarnetwork.node.job.AbstractJob.java

/**
 * Helper method for logging a Throwable.
 * /*from   ww w  .jav  a 2s.c om*/
 * @param e
 *        the exception
 */
protected void logThrowable(Throwable e) {
    final String name = (getName() == null ? getClass().getSimpleName() : getName());
    Throwable root = e;
    while (root.getCause() != null) {
        root = root.getCause();
    }
    final Object[] logParams;
    if (log.isDebugEnabled()) {
        // include stack trace with log message in Debug
        logParams = new Object[] { root.getClass().getSimpleName(), name, e.toString(), e };
    } else {
        logParams = new Object[] { root.getClass().getSimpleName(), name, e.getMessage() };
    }
    log.error("{} in job {}: {}", logParams);
}

From source file:com.hurence.logisland.serializer.BytesArraySerializer.java

public Record deserialize(InputStream objectDataInput) {
    try {/*from w  ww. j  a  v a2  s .  c  om*/
        Record record = new StandardRecord();
        byte[] bytes = IOUtils.toByteArray(objectDataInput);
        record.setField(FieldDictionary.RECORD_VALUE, FieldType.BYTES, bytes);
        return record;
    } catch (Throwable t) {
        throw new RecordSerializationException(t.getMessage(), t.getCause());
    }
}

From source file:org.apache.trafficcontrol.client.trafficops.TOSessionTest.java

@Test(expected = LoginException.class)
public void test401Response() throws Throwable {
    HttpResponse resp = Mockito.mock(HttpResponse.class);
    Mockito.when(resp.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_0, 401, "Not Auth"));

    final CompletableFuture<HttpResponse> f = new CompletableFuture<>();
    f.complete(resp);/*from w w w.ja v  a2  s  . co m*/

    Mockito.doReturn(f).when(sessionMock).execute(Mockito.any(RequestBuilder.class));

    TOSession session = TOSession.builder().fromURI(baseUri).setRestClient(sessionMock).build();

    try {
        session.getDeliveryServices().get();
    } catch (Throwable e) {
        throw e.getCause();
    }
}

From source file:com.evolveum.midpoint.test.IntegrationTestTools.java

public static boolean hasInMessageRecursive(Throwable e, String substring) {
    if (e.getMessage().contains(substring)) {
        return true;
    }/*from   w w  w . j a va  2s .c  o  m*/
    if (e.getCause() != null) {
        return hasInMessageRecursive(e.getCause(), substring);
    }
    return false;
}

From source file:com.googlecode.ehcache.annotations.integration.ConfigurationFailureTest.java

/**
 * Test verifies behavior when the "default-cache-key-generator" attribute
 * on the main config element refers to a bean name that does not exist. 
 *///w w  w  . jav a  2s . co  m
@Test
public void testMissingOverrideDefaultCacheKeyGenerator() {
    try {
        new ClassPathXmlApplicationContext("/noOverrideDefaultCacheKeyGeneratorTestContext.xml");
        Assert.fail("Test should have failed with due to missing bean for default-cache-key-generator");
    } catch (BeanCreationException bce) {
        Throwable cause = bce;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }

        final StringWriter stack = new StringWriter();
        cause.printStackTrace(new PrintWriter(stack));
        Assert.assertTrue(
                "Root cause must be NoSuchBeanDefinitionException but was: " + cause + "\n " + stack.toString(),
                cause instanceof NoSuchBeanDefinitionException);
    }
}

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

public Throwable getInitialCause() {
    Throwable initialCause = getCause();
    if (initialCause != null) {
        while (initialCause.getCause() != null) {
            initialCause = initialCause.getCause();
        }//from   w  w w . j  av  a 2 s .com
        return initialCause;
    }
    return this;
}