A team is developing a Java application that uses many third-party libraries. One library throws a checked exception that is not declared in its method signature. Which approach best handles this situation?
This satisfies the compiler and preserves the exception chain.
Why this answer
A checked exception that is not declared in a method signature cannot be propagated without handling it. Wrapping it in a RuntimeException (an unchecked exception) bypasses the compiler's checked-exception enforcement, allowing the exception to be thrown without modifying the method signature. This is a common pattern when integrating third-party libraries that throw checked exceptions from methods that do not declare them.
Exam trap
The trap here is that candidates may think they can simply declare the library's exception in their own method signature (Option B), but the compiler requires the exception to be actually declared in the library's method signature, which it is not, making this approach invalid.
How to eliminate wrong answers
Option A is wrong because ignoring a checked exception that is not declared in the method signature will cause a compilation error; the compiler enforces that checked exceptions must be either caught or declared. Option B is wrong because you cannot declare an exception in your method signature that the library method does not declare; the compiler will not allow you to declare an exception that is not actually thrown by the called method. Option D is wrong because catching and logging the exception then continuing execution may mask critical failures, and it does not address the fact that the exception is not declared in the method signature, which still prevents compilation.