Skip to content
Sharp

Networking · interview question

Which method can be used to handle exceptions that occur during a CompletableFuture's execution?

Multiple choiceHardchapter-11-curatedpremiumnetworkingjackson-objectmapper
java
completableFuture.exceptionally(ex -> { return "Fallback result due to: " + ex.getMessage(); });
Choose one answer
Answer and explanation

Correct answer

C. Exceptionally

Why

The exceptionally method is used in CompletableFuture to handle exceptions. It provides a way to define a fallback or alternative action if the initial computation fails, ensuring that exceptions do not go unhandled.

Test yourself on Networking

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

Start free test
All Networking questions →