1Z0-829 Handling Exceptions Practice Question
A method reads a file and throws IOException. Which of the following is the correct way to declare the method?
⚠ Common exam trap
Test-takers frequently confuse checked and unchecked exceptions, or think that declaring a broader exception like Exception is acceptable, but the exam tests precise exception handling where the exact checked exception must be declared.
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
✓
public void readFile() throws IOException { ... }
The method explicitly declares that it throws IOException, which is a checked exception. In Java, if a method can throw a checked exception like IOException, it must either handle it with a try-catch block or declare it in the throws clause. This allows the caller to handle the exception appropriately.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
public void readFile() throws RuntimeException { ... }
Why it's wrong here
Wrong exception type; IOException is checked.
- ✗
public void readFile() throws Exception { ... }
Why it's wrong here
Too generic; should be specific IOException.
- ✗
public void readFile() { ... } // assumes try-catch inside
Why it's wrong here
Must handle or declare the checked exception.
- ✓
public void readFile() throws IOException { ... }
Why this is correct
Correctly declares IOException.
Go deeper
Related to this question
About these practice questions
This 1Z0-829 question is part of Courseiva's 513-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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-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.