Courseiva
Handling ExceptionsmediumMultiple ChoiceObjective-mapped

1Z0-829 Handling Exceptions Practice Question

Consider the following code snippet:

try { // some code

} catch (IOException e) {

// handle

} catch (FileNotFoundException e) { // Line X

// handle

}

What will be the result?

⚠ Common exam trap

It's easy for candidates to think the code compiles and the second catch simply never runs, but Java enforces this at compile time to prevent unreachable code, not just at runtime.

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

Compilation fails at Line X with an error about an exception already caught.

In Java, when catching exceptions, the more specific exception subclass must be caught before the more general superclass. FileNotFoundException is a subclass of IOException, so catching IOException first makes the catch for FileNotFoundException unreachable, causing a compilation error at Line X.

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 code compiles and runs without issues.

    Why it's wrong here

    FileNotFoundException is a subclass of IOException, so the order causes unreachable code.

  • The code compiles but throws a ClassCastException at runtime.

    Why it's wrong here

    No runtime exception related to catch ordering.

  • The code compiles but the second catch never executes.

    Why it's wrong here

    Compilation fails, so it never runs.

  • Compilation fails at Line X with an error about an exception already caught.

    Why this is correct

    Correct: FileNotFoundException is already caught by IOException.

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 →

How Courseiva writes practice questions · Editorial policy

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.