Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 8 Level 1 / CompletableFuture in general #571

Open
nowknowing opened this issue Nov 30, 2020 · 2 comments
Open

Lab 8 Level 1 / CompletableFuture in general #571

nowknowing opened this issue Nov 30, 2020 · 2 comments
Labels
🖱️ Java General Questions with regards to Java or its API

Comments

@nowknowing
Copy link

Description

How do we catch the IO exception expected from the first task run asynchronously?
image
image

Topic:

Asynchronous

Screenshots (if any):

Insert Images here if necessary

@nowknowing nowknowing added the 🖱️ Java General Questions with regards to Java or its API label Nov 30, 2020
@nowknowing nowknowing reopened this Nov 30, 2020
@gabrielloye
Copy link

I don't think you need to catch the IOException/InterruptedException? The test cases on CodeCrunch seem to pass without handling these 2

@nowknowing nowknowing changed the title Lab 8 Level 1 Lab 8 Level 1 / CompletableFuture in general Nov 30, 2020
@tjoewel
Copy link

tjoewel commented Nov 30, 2020

More generally, CompletableFuture is a functor and a monad (lecture 12 pg 17). What the sendAsync method does is return a HttpResponse wrapped in a CompletableFuture. If you look at the java API for HttpClient, you will see that send throws some exceptions of which IOException is one of them. However, SendAsync only throws IllegalArgumentException. All other exceptions would be handled in CompletableFuture similar to how the Sandbox in lecture 7 handles exceptions. If there is an IOException, it would be thrown when you do CompletableFuture.join(), so simply assigning a variable a HttpResponse wrapped in a CompletableFuture will not throw a IOException. Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖱️ Java General Questions with regards to Java or its API
Projects
None yet
Development

No branches or pull requests

3 participants