Exceptions · interview question
Which principle is important when deciding between a checked and unchecked exception for a custom exception?
Multiple choiceHardchapter-6-curatedpremiumexceptionscustom-exceptions
Answer and explanation
Correct answer
A. Whether the caller can reasonably recover
Why
If the caller can reasonably be expected to recover from an error condition, a checked exception should be used. If the error is programming-related and not usually recoverable, an unchecked exception is appropriate.
Test yourself on Exceptions
A free test with instant, explained results. No account needed.
More Exceptions questions
- When designing a Java API, how should exceptions be documented?
- Why can catching the Exception class in Java become a real problem?
- How can fail-fast validation impact the design of a Java class intended for secure financial transactions?
- Why can overusing checked exceptions in a library become a problem in production code?
- In which scenario does exception wrapping make code more reliable?
- What role does the 'finally' block serve in Java exception handling?