title: How to collect both success and error within CompletableFutures?
body: <p>I want to send multiple requests in parallel to a webservice. The results should be collected by success + error, and can then be further analyzed by the caller.</p>
  
  <pre><code>public Map.Entry&lt;Rsp, Errors&gt; sendApiRequests(List&lt;Req&gt; reqs) {
      //will mostly remain null as errors won't occur frequently
      List&lt;Rsp&gt; errors = null;
  
      List&lt;CompletableFuture&lt;Rsp&gt;&gt; futures =
              reqs.stream()
                  .map(req -&gt; CompletableFuture.supplyAsync(() -&gt; send(req))
                          .exceptionally(ex -&gt; {
                              //TODO this fails, because list should be final for it.
                              //but don't want to instantiate as mostly will remain just null
                              if (errors == null) errors = new ArrayList&lt;&gt;();
                              errors.add(req);
                          }))
                  .collect(Collectors.toList());
  
      //send api requests in parallel
      List&lt;Rsp&gt; responses = futures.stream()
              .map(CompletableFuture::join)
              .collect(Collectors.toList());
  
      //TODO how to collect the errors? each error should also provide the underlying Req that caused the failure.
      //pending requests should not be aborted if any throwns an exception
      return new SimpleEntry(responses, errors);
  }
  </code></pre>
  
  <p>Question: how can I bet collect all responses, but also collect exceptions thrown during the <code>send()</code> method?</p>
  
  <p>My goal is not to return two lists: one containing all succeeded responses, and one containing errors.</p>