Example usage for java.lang RuntimeException getSuppressed

List of usage examples for java.lang RuntimeException getSuppressed

Introduction

In this page you can find the example usage for java.lang RuntimeException getSuppressed.

Prototype

public final synchronized Throwable[] getSuppressed() 

Source Link

Document

Returns an array containing all of the exceptions that were suppressed, typically by the try -with-resources statement, in order to deliver this exception.

Usage

From source file:org.zalando.jpa.validation.ConstraintViolationExceptionLogger.java

@Override
public DataAccessException translateExceptionIfPossible(final RuntimeException ex) {
    Throwable[] suppressedExceptions = ex.getSuppressed();
    for (Throwable t : suppressedExceptions) {
        LOG.warn("SUPPRESSED EXCEPTION --> : {} ", t.getClass().getName());
    }//from www .  j  a  v a2 s . com

    if (ex instanceof ConstraintViolationException) {
        violationPrinter.printValidationErrors((ConstraintViolationException) ex);
    }

    return null;
}

From source file:org.elasticsearch.client.SyncResponseListenerTests.java

public void testOnFailure() throws Exception {
    RestClient.SyncResponseListener syncResponseListener = new RestClient.SyncResponseListener(10000);
    RuntimeException firstException = new RuntimeException("first-test");
    syncResponseListener.onFailure(firstException);
    try {//from www .j av a  2s  .  c  o  m
        syncResponseListener.get();
        fail("get should have failed");
    } catch (RuntimeException e) {
        assertSame(firstException, e);
    }

    RuntimeException secondException = new RuntimeException("second-test");
    try {
        syncResponseListener.onFailure(secondException);
    } catch (IllegalStateException e) {
        assertEquals(e.getMessage(), "exception is already set");
    }
    try {
        syncResponseListener.get();
        fail("get should have failed");
    } catch (RuntimeException e) {
        assertSame(firstException, e);
    }

    Response response = mockResponse();
    syncResponseListener.onSuccess(response);
    try {
        syncResponseListener.get();
        fail("get should have failed");
    } catch (IllegalStateException e) {
        assertEquals("response and exception are unexpectedly set at the same time", e.getMessage());
        assertNotNull(e.getSuppressed());
        assertEquals(1, e.getSuppressed().length);
        assertSame(firstException, e.getSuppressed()[0]);
    }
}

From source file:org.nuxeo.ecm.core.cache.CacheRegistry.java

public void start() {
    RuntimeException errors = new RuntimeException("Cannot start caches, check suppressed error");
    for (CacheDescriptor desc : caches.values()) {
        try {/*from   w  w w.  j av  a 2s. co  m*/
            desc.start();
        } catch (RuntimeException cause) {
            errors.addSuppressed(cause);
        }
    }
    if (errors.getSuppressed().length > 0) {
        throw errors;
    }
}

From source file:org.nuxeo.ecm.core.cache.CacheRegistry.java

public void stop() {
    RuntimeException errors = new RuntimeException("Cannot stop caches, check suppressed error");
    for (CacheDescriptor desc : caches.values()) {
        try {/* www  .  j  a v  a 2 s  .com*/
            desc.stop();
        } catch (RuntimeException cause) {
            errors.addSuppressed(cause);
        }
    }
    if (errors.getSuppressed().length > 0) {
        throw errors;
    }
}

From source file:org.nuxeo.ecm.core.schema.SchemaManagerImpl.java

protected void recomputeSchemas() {
    schemas.clear();//w  w w .  jav a 2 s .  co m
    uriToSchema.clear();
    prefixToSchema.clear();
    RuntimeException errors = new RuntimeException("Cannot load schemas");
    for (SchemaBindingDescriptor sd : allSchemas) {
        try {
            copySchema(sd);
        } catch (Exception error) {
            if (error instanceof InterruptedException) {
                // restore interrupted status
                Thread.currentThread().interrupt();
            }
            errors.addSuppressed(error);
        }
    }
    for (SchemaBindingDescriptor sd : allSchemas) {
        try {
            loadSchema(sd);
        } catch (Exception error) {
            if (error instanceof InterruptedException) {
                // restore interrupted status
                Thread.currentThread().interrupt();
            }
            errors.addSuppressed(error);
        }
    }
    if (errors.getSuppressed().length > 0) {
        throw errors;
    }
}

From source file:org.nuxeo.ecm.core.storage.sql.TestSQLBackend.java

@Test
public void testDeadlockDetection() throws Exception {
    Session session = repository.getConnection();
    Node root = session.getRootNode();
    session.addChildNode(root, "doc", null, "TestDoc", false);
    session.save();// www .  j  a  v  a  2s.c om
    DeadlockTestJob r1 = new DeadlockTestJob("foo1");
    DeadlockTestJob r2 = new DeadlockTestJob("foo2");
    try {
        LockStepJob.run(r1, r2);
        fail("Expected ConcurrentUpdateStorageException");
    } catch (RuntimeException e) {
        Throwable[] suppressed = e.getSuppressed();
        assertNotNull(suppressed);
        assertTrue(suppressed[0].toString(), suppressed[0] instanceof ConcurrentUpdateStorageException);
    }
}

From source file:org.nuxeo.runtime.jtajca.NuxeoContainer.java

public static synchronized void resetConnectionManager() {
    RuntimeException errors = new RuntimeException("Cannot reset connection managers");
    for (ConnectionManagerWrapper wrapper : connectionManagers.values()) {
        try {/*w w w.  j ava2s . c o  m*/
            wrapper.reset();
        } catch (RuntimeException cause) {
            errors.addSuppressed(cause);
        }
    }
    if (errors.getSuppressed().length > 0) {
        throw errors;
    }
}