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> getDogs(List<String> tagIds, String ownerId)
throws InvalidRequestException, DependencyFailureException {
List<CompletableFuture<Dog>> futures = new ArrayList<>(tagIds.size());
List<Dog> responses = new ArrayList<>(tagIds.size());
for(String tagId : tagIds) {
futures.add(CompletableFuture.supplyAsync(() -> {
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(CompletableFuture::join)
.collect(Collectors.toList());
}
Any idea what I'm missing?