Skip to content
Sharp

Exceptions · interview question

Which of the following is a valid reason to catch and rethrow an exception as a different type?

Multiple choiceMediumchapter-6-curatedpremiumexceptionschecked-vs-unchecked-exceptions
Choose one answer
Answer and explanation

Correct answer

C. To map it to a higher-level domain exception

Why

Catching and rethrowing an exception as a higher-level domain exception helps in abstracting the error handling and aligning it with the domain logic. This approach makes the API more intuitive for the caller, focusing on business logic rather than technical details.

Test yourself on Exceptions

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

Start free test
All Exceptions questions →