Exam 1z0-819 All QuestionsBrowse all questions from this exam
Question 145

Given the code fragment:

Which two actions, independently, enable the code to compile? (Choose two.)

    Correct Answer: D, F

    The provided code fragment attempts to handle a FileInputStream, which can throw both FileNotFoundException and IOException. For the code to compile, it has to handle these exceptions correctly. Replacing the catch block with a generic 'catch (Exception e)' will handle all exceptions, including FileNotFoundException and IOException, thus enabling the code to compile. Additionally, adding 'throws IOException' to the main method signature allows the method to throw IOException, covering any IO-related exceptions without handling them directly within the try-catch block. Therefore, the two independent actions that enable the code to compile are replacing the catch block with 'catch (Exception e) {}' and adding 'throws IOException' in the main method declaration.

Discussion
OmnisumemOptions: DF

Tested: D (catch (Exception e) {}) and F.

ASPushkinOptions: DF

The question is that AutoCloseable interface has void close() throws Exception. Legacy Closeable interface has close() throws IOException the answer is DF but why ?

d7bb0b2Options: DF

Caht exception and throws IoExp in declaration compile

StavokOptions: DF

D & F Are correct TESTED

KiraguJohnOptions: DF

D,F There is an auto-closeable resource that needs IOException to be either declared in the method or be added in the catch block, if you only use Exception on the catch you will be fine since it is the parent class for all Exceptions

KiraguJohnOptions: CF

There is an auto-closeable resource that needs IOException to be either declared in the method or be added in the catch block