Example usage for java.lang InterruptedException addSuppressed

List of usage examples for java.lang InterruptedException addSuppressed

Introduction

In this page you can find the example usage for java.lang InterruptedException addSuppressed.

Prototype

public final synchronized void addSuppressed(Throwable exception) 

Source Link

Document

Appends the specified exception to the exceptions that were suppressed in order to deliver this exception.

Usage

From source file:Main.java

/**
 * Await all of the future tasks indefinitely.
 * The exceptions are combined into a single exception
 * (by adding subsequent exceptions as addsuppressed).
 * @param tasks the sequence of tasks/*w w w  .ja va2s.  c o m*/
 * @throws ExecutionException if the task failed
 * @throws InterruptedException if the wait was interrupted
 */
public static void awaitAll(Iterable<? extends Future<?>> tasks)
        throws ExecutionException, InterruptedException {
    ExecutionException ee = null;
    InterruptedException ie = null;
    for (Future<?> f : tasks) {
        try {
            f.get();
        } catch (ExecutionException ex) {
            if (ee != null) {
                ee.addSuppressed(ex);
            } else {
                ee = ex;
            }
        } catch (InterruptedException ex) {
            if (ie != null) {
                ie.addSuppressed(ex);
            } else {
                ie = ex;
            }
        }
    }
    if (ee != null && ie != null) {
        ee.addSuppressed(ie);
        throw ee;
    } else if (ee != null) {
        throw ee;
    } else if (ie != null) {
        throw ie;
    }
}