Bird
0
0

What will happen if a method throws a checked exception but does not declare it or catch it?

medium📝 Predict Output Q5 of 15
Java - Exception Handling
What will happen if a method throws a checked exception but does not declare it or catch it?
public void read() {
  throw new IOException();
}
ACompilation error
BRuntime exception thrown
CMethod runs without error
DUnchecked exception thrown
Step-by-Step Solution
Solution:
  1. Step 1: Understand checked exception rules

    Checked exceptions must be declared or caught; otherwise, compiler error occurs.
  2. Step 2: Analyze method code

    Method throws IOException but neither declares nor catches it, causing compilation failure.
  3. Final Answer:

    Compilation error -> Option A
  4. Quick Check:

    Checked exceptions must be declared or caught [OK]
Quick Trick: Unchecked exceptions don't require declaration; checked do [OK]
Common Mistakes:
  • Assuming runtime exception thrown
  • Ignoring compiler checks
  • Confusing checked with unchecked exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes