Bird
0
0

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

medium📝 Predict Output Q5 of 15
Java - Custom Exceptions
What will happen if a method throws a checked exception but the caller does not handle or declare it?
void caller() {
  callee();
}
void callee() throws IOException {
  throw new IOException();
}
ACompilation error due to unhandled checked exception
BRuntime exception occurs
CException is ignored and program runs
DProgram terminates silently
Step-by-Step Solution
Solution:
  1. Step 1: Identify checked exception rules

    Checked exceptions must be either caught or declared in the calling method's signature.
  2. Step 2: Check caller method declaration

    The caller method neither catches nor declares the IOException, causing a compilation error.
  3. Final Answer:

    Compilation error due to unhandled checked exception -> Option A
  4. Quick Check:

    Checked exceptions cause compile errors if not handled [OK]
Quick Trick: Checked exceptions must be caught or declared [OK]
Common Mistakes:
  • Assuming runtime exception instead of compile error
  • Thinking exceptions are ignored
  • Believing program terminates silently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes