Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q6 of 15
C Sharp (C#) - Exception Handling
Identify the error in this code snippet:
try {
  // some code
} catch (Exception ex) {
  Console.WriteLine("Error caught");
} catch (ArgumentNullException ex) {
  Console.WriteLine("Null argument");
}
AArgumentNullException catch block unreachable
BSyntax error in catch blocks
CMissing finally block
DNo error
Step-by-Step Solution
Solution:
  1. Step 1: Analyze catch block order

    The general Exception catch block comes before the more specific ArgumentNullException catch block.
  2. Step 2: Understand catch block reachability

    Since ArgumentNullException inherits from Exception, the first catch block catches all exceptions, making the second unreachable.
  3. Final Answer:

    ArgumentNullException catch block unreachable -> Option A
  4. Quick Check:

    Specific catch must come before general catch [OK]
Quick Trick: Place specific exceptions before general ones in catch [OK]
Common Mistakes:
MISTAKES
  • Placing general catch before specific
  • Ignoring unreachable code warnings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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