Title: CompletableFutures and exception handling in Java
Tags: java;exception;completable-future
Question: I'm new to the whole CompletableFutures business. Currently, I'm trying to populate a futures list with objects retrieved from a service call and then return the list itself. However, I'm getting 
```error: unreported exception InvalidRequestException; must be caught or declared to be thrown``` and ```unreported exception DependencyFailureException; must be caught or declared to be thrown``` errors even though I'm using a try/catch block and declare the exceptions.
Here's what I have so far:

```public List<Dog&gt; getDogs(List<String&gt; tagIds, String ownerId) 
        throws InvalidRequestException, DependencyFailureException {

    List<CompletableFuture<Dog&gt;&gt; futures = new ArrayList<&gt;(tagIds.size());
    List<Dog&gt; responses = new ArrayList<&gt;(tagIds.size());

    for(String tagId : tagIds) {
        futures.add(CompletableFuture.supplyAsync(() -&gt; {
            try {
                return getDog(tagId, ownerId);
            } catch (InvalidRequestException ire) {
                throw new InvalidRequestException("An invalid request to getDog", ire);
            } catch (DependencyFailureException dfe) {
                throw new DependencyFailureException("A dependency failure occurred during a getDog call", dfe);
            }
        }));
    }
    return futures.stream()
          .map(CompletableFutur181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16join)
          .collect(Collectors.toList());
}
```

Any idea what I'm missing?

Comment: Presumably your `InvalidRequestException` and `DependencyFailureException` types are checked. The `Supplier` functional interface does not declare throwing any checked exceptions, let alone your custom ones. You'll need to handle them internally or rethrow them wrapped in an unchecked exception type.

Comment: An example of what? Handling is up to you, whatever process you've setup in your application. Wrapping in an uncheckedexception is also discussed [here](http://stackoverflow.com/questions/484794/wrapping-a-checked-exception-into-an-unchecked-exception-in-java).

Comment: Sotirios Delimanolis, do you have an example of how to go about doing something like that?



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:07/08/16', 'FavoriteCount': 0.0, 'PostTypeId': 1, 'Tags': '<java><exception><completable-future>', 'Title': 'CompletableFutures and exception handling in Java', 'ViewCount': 117, 'id': 38276311, 'user_AboutMe': None, 'user_AccountId': 6198973.0, 'user_DisplayName': 'wonderv', 'user_Reputation': 143.0, 'user_Views': 40.0, 'user_id': 6567237.0}}