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) when {
    Console.WriteLine(ex.Message);
}
AIncorrect exception type in catch
Btry block is empty
CConsole.WriteLine cannot be used in catch
DMissing condition expression after when
Step-by-Step Solution
Solution:
  1. Step 1: Review catch with when syntax

    The when clause requires a boolean condition expression after it.
  2. Step 2: Identify the error in the snippet

    The code has when without any condition, which is a syntax error.
  3. Final Answer:

    Missing condition expression after when -> Option D
  4. Quick Check:

    when must have condition expression [OK]
Quick Trick: when must be followed by a boolean condition [OK]
Common Mistakes:
MISTAKES
  • Leaving when empty
  • Using when without parentheses
  • Confusing when with catch block body

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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