Exceptions · interview question
Consider the following code snippet. What is the primary issue with the exception handling?
Multiple choiceHardchapter-6-curatedpremiumexceptionscause-chaining-and-error-context
try { // some code } catch (IOException e) { throw new OrderProcessingException("Order failed"); }Answer and explanation
Correct answer
D. The original exception cause is lost.
Why
The code loses the original exception cause by not passing it to the new exception, which makes it difficult to trace the error's origin.
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?