Bird
0
0

Consider this code:

medium📝 Predict Output Q5 of 15
C Sharp (C#) - Exception Handling
Consider this code:
try {
    Console.WriteLine("X");
} catch (Exception ex) {
    Console.WriteLine("Y");
} finally {
    Console.WriteLine("Z");
}

What is the output?
AX Y Z
BX Z
CY Z
DZ only
Step-by-Step Solution
Solution:
  1. Step 1: Check if exception occurs

    No exception is thrown in try, so catch block is skipped.
  2. Step 2: Identify executed blocks

    Try prints "X", finally prints "Z".
  3. Final Answer:

    X Z -> Option B
  4. Quick Check:

    No exception = try + finally output [OK]
Quick Trick: Catch runs only on exceptions; finally always runs [OK]
Common Mistakes:
MISTAKES
  • Assuming catch runs without exception
  • Ignoring finally output
  • Mixing order of outputs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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