Courseiva
Exception Handling and Development ToolshardMultiple ChoiceObjective-mapped

1Z0-811 Exception Handling and Development Tools Practice Question

Exhibit

public class ResourceHandler {
    public void process() throws IOException {
        try (FileInputStream fis = new FileInputStream("data.txt");
             BufferedReader br = new BufferedReader(new InputStreamReader(fis))) {
            // read file
        } catch (IOException e) {
            throw e;
        }
    }
}

Consider the following code: ```java

import java.io.*;

public class Test {
    public static void main(String[] args) throws IOException {

try (FileInputStream fis = new FileInputStream("test.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fis))) { System.out.println(br.readLine());

} catch (IOException e) {

System.out.println("Error");

}
    }
}

``` Which statement about this code is true?

⚠ Common exam trap

The 1Z0-811 exam often tests the misconception that a catch block is required in try-with-resources, but the catch block is optional and only needed if you want to handle exceptions locally rather than propagating them with `throws`.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

The catch block is unnecessary.

The code likely uses a try-with-resources statement, which automatically closes resources. The catch block is unnecessary since the resources are closed automatically, and the exception can be declared to be thrown. The code compiles without the catch block, and resource management is handled by the try-with-resources construct.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • The resource 'br' is not closed properly.

    Why it's wrong here

    Try-with-resources closes both resources automatically, in reverse order.

  • The code will not compile because of the throws clause.

    Why it's wrong here

    The method declares it throws IOException, which is correct and compiles.

  • The resource 'fis' is closed before 'br'.

    Why it's wrong here

    Resources are closed in the reverse order of declaration, so 'br' is closed first, then 'fis'.

  • The catch block is unnecessary.

    Why this is correct

    The try-with-resources already ensures proper handling; the catch block just rethrows, making it redundant.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.