Bird
0
0

What will be the output of this C# code?

medium📝 Predict Output Q4 of 15
C Sharp (C#) - Exception Handling
What will be the output of this C# code?
try {
    Console.WriteLine("A");
    throw new Exception();
    Console.WriteLine("B");
} catch {
    Console.WriteLine("C");
} finally {
    Console.WriteLine("D");
}
AA B C D
BC D
CA C D
DA D
Step-by-Step Solution
Solution:
  1. Step 1: Trace try block execution

    "A" is printed, then exception is thrown, so "B" is skipped.
  2. Step 2: Catch and finally blocks run

    The catch block prints "C", then finally prints "D".
  3. Final Answer:

    A C D -> Option C
  4. Quick Check:

    Exception thrown = catch + finally run [OK]
Quick Trick: Exception stops try; catch then finally run [OK]
Common Mistakes:
MISTAKES
  • Assuming code after throw runs
  • Ignoring finally block output
  • Thinking catch block is skipped

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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