Bird
0
0

Find the problem in this code:

medium📝 Debug Q7 of 15
C Sharp (C#) - Exception Handling

Find the problem in this code:

try {
  // code
} catch (ArgumentException ex) {
  // handle
} catch {
  // handle all
} catch (Exception ex) {
  // handle
}
AMissing finally block causes error.
BThe catch block without exception type must be last.
CCatch blocks can be in any order.
DMultiple catch blocks with same exception type.
Step-by-Step Solution
Solution:
  1. Step 1: Understand catch block without exception type

    A catch block without an exception type catches all exceptions and must be last.
  2. Step 2: Identify incorrect order

    Here, the catch-all block is before a specific Exception catch, which is invalid and causes unreachable code.
  3. Final Answer:

    The catch block without exception type must be last. -> Option B
  4. Quick Check:

    Catch-all block must be last [OK]
Quick Trick: Catch-all catch block goes last [OK]
Common Mistakes:
MISTAKES
  • Placing catch-all before specific catches
  • Assuming catch-all can be anywhere
  • Confusing finally with catch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes