Oracle Certified Professional Java Se 11 Developer · Free Practice Question Hard

Question 57

Question ID: UKOCP61623


Given code of Test.java file:


What will be the result of compiling and executing Test class?

  • A IOException
  • B SQLException
  • C Compilation error
Reveal correct answer

Correct answer: A

Explanation

UKOCP61623:

execute() method throws an instance of SQLException.


Just before finding the matching handler, Java runtime executes close() method. This method throws an instance of IOException but it gets suppressed and an instance of SQLException is thrown.


e.getSuppressed() returns Throwable [] whose 1st element is the instance of suppressed exception, IOException.


'e.getSuppressed()[0].getMessage()' prints IOException on to the console.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need