Bird
0
0

Identify the problem in this code:

medium📝 Debug Q7 of 15
Java - Exception Handling

Identify the problem in this code:

try {
    System.out.println("Start");
} catch (Exception e) {
    System.out.println("Catch");
}
Atry block must have either catch or finally block, so this is correct
BMissing finally block causes compilation error
Ctry block must have finally block if catch is present
Dtry block without finally causes runtime error
Step-by-Step Solution
Solution:
  1. Step 1: Recall try block requirements

    Try block must be followed by at least one catch or finally block.
  2. Step 2: Analyze given code

    Code has try followed by catch, which is valid syntax.
  3. Final Answer:

    try block must have either catch or finally block, so this is correct -> Option A
  4. Quick Check:

    try with catch only = valid [OK]
Quick Trick: try needs catch or finally [OK]
Common Mistakes:
  • Thinking finally is mandatory
  • Assuming missing finally causes error
  • Confusing runtime and compile errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes