List of usage examples for java.lang InterruptedException addSuppressed
public final synchronized void addSuppressed(Throwable exception)
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; } }