title: Catch exception from parallel stream
body: <p>I have a bunch of columns as string arrays from a csv file. Now I want to parse them. Since this parsing requires date parsing and other not so fast parsing techniques I was thinking about parallelism (I timed it, it takes some time). My simple approach:</p>
  
  <pre><code>Stream.of(columns).parallel().forEach(column -&gt; 
      result[column.index] = parseColumn(valueCache[column.index], column.type));
  </code></pre>
  
  <p>Columns contains <code>ColumnDescriptor</code> elements which simply has two attributes, the column index to be parsed and the type which defines how to parse it. Nothing else. result is an Object array which takes the resulting arrays.</p>
  
  <p>The problem is now that the parse function throws a ParseException, that I handle further up the call stack. Since we are in parallel here it can't just be thrown. What is the best way to handle this?</p>
  
  <p>I have this solution, but I kind of cringe reading it. What would be a better way to do it?</p>
  
  <pre><code>final CompletableFuture&lt;ParseException&gt; thrownException = new CompletableFuture&lt;&gt;();
  Stream.of(columns).parallel().forEach(column -&gt; {
      try {
          result[column.index] = parseColumn(valueCache[column.index], column.type);
      } catch (ParseException e) {
          thrownException.complete(e);
      }});
  
  if(thrownException.isDone())
      //only can be done if there is a value set.
      throw thrownException.getNow(null);
  </code></pre>
  
  <p>Notes: I do not need all the exceptions. If I parse them sequentially I will also only get one anyway. So that is ok.</p>