1Z0-829 Handling Exceptions Practice Question
Exhibit
Refer to the exhibit. Compilation output: Error: unreported exception java.io.IOException; must be caught or declared to be thrown at Test.main(Test.java:5)
Given the exhibit showing a compilation error at line 5 of Test.java, which of the following code fragments could be at that line?
⚠ Common exam trap
The trap here is that candidates often forget that checked exceptions must be handled or declared, and mistakenly think any code that throws an exception will compile as long as it is inside a method, ignoring the compiler's requirement for checked exception handling.
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
✓
FileInputStream fis = new FileInputStream("test.txt");
The code at line 5 is a checked exception (FileNotFoundException) that must be handled or declared. The compilation error indicates that the method containing line 5 does not handle or declare this checked exception, which is required by the Java compiler.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
FileInputStream fis = new FileInputStream("test.txt");
Why this is correct
FileInputStream constructor throws FileNotFoundException (subclass of IOException).
- ✗
int x = 5;
Why it's wrong here
No checked exception.
- ✗
try { ... } catch (Exception e) { }
Why it's wrong here
Handles the exception.
- ✗
System.out.println("Hello");
Why it's wrong here
No checked exception.
Go deeper
Related to this question
About these practice questions
One of 513 original 1Z0-829 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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-829 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-829 exam.