Bird
0
0

Why would a developer use a when clause in a catch block in C#?

easy🧠 Conceptual Q1 of 15
C Sharp (C#) - Exception Handling

Why would a developer use a when clause in a catch block in C#?

ATo rethrow an exception automatically
BTo catch multiple exceptions in a single block
CTo filter exceptions based on a condition before handling them
DTo declare a finally block inside catch
Step-by-Step Solution
Solution:
  1. Step 1: Understand the purpose of when

    The when clause allows conditional filtering of exceptions.
  2. Step 2: Analyze options

    To filter exceptions based on a condition before handling them correctly states filtering exceptions based on a condition. Options B, C, and D describe unrelated behaviors.
  3. Final Answer:

    To filter exceptions based on a condition before handling them -> Option C
  4. Quick Check:

    Using when filters exceptions conditionally [OK]
Quick Trick: Use when to conditionally catch exceptions [OK]
Common Mistakes:
MISTAKES
  • Thinking when catches multiple exceptions at once
  • Confusing when with finally block
  • Assuming when rethrows exceptions automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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