1Z0-811 Exception Handling and Development Tools Practice Question
Exhibit
error: unreported exception java.io.IOException; must be caught or declared to be thrown
br.readLine();
^Refer to the exhibit. A Java source file fails to compile with the given error. What change should be made to fix the error?
⚠ Common exam trap
Oracle often tests the distinction between checked and unchecked exceptions, and the trap here is that candidates mistakenly think importing the class or using a `finally` block will resolve the compile-time error, when the actual fix is to either catch or declare the checked exception.
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
✓
Add a throws IOException clause to the enclosing method
The code is calling a method (e.g., `Files.readString()`, `BufferedReader.readLine()`, or similar) that throws a checked `IOException`. In Java, checked exceptions must be either caught with a try-catch block or declared in the enclosing method's `throws` clause. Option A adds the `throws IOException` declaration, which correctly propagates the exception to the caller, satisfying the compiler's requirement.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Add a throws IOException clause to the enclosing method
Why this is correct
Declaring the exception allows it to propagate, fixing the compilation error.
- ✗
Wrap the code in a try-catch for NullPointerException
Why it's wrong here
The required catch is for IOException, not NullPointerException.
- ✗
Change the method to use a finally block
Why it's wrong here
A finally block alone does not handle the exception.
- ✗
Import the java.io.IOException class
Why it's wrong here
Import is needed but doesn't solve the unhandled exception; the error is about handling.
Go deeper
Related to this question
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 →
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.