Skip to content
Sharp

Networking · interview question

How can you safely handle an HttpTimeoutException when using CompletableFuture?

Multiple choiceMediumchapter-11-curatedpremiumnetworkingtimeouts-and-retries
Choose one answer
Answer and explanation

Correct answer

D. Using exceptionally() to handle exceptions

Why

The exceptionally() method allows you to define a recovery or compensation action in case the CompletableFuture encounters an exception, such as an HttpTimeoutException. This ensures that the exception is handled gracefully without crashing the application.

Test yourself on Networking

A free test with instant, explained results. No account needed.

Start free test
All Networking questions →