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("Try block");
    throw new Exception();
} catch {
    Console.WriteLine("Catch block");
} finally {
    Console.WriteLine("Finally block");
}
ATry block Catch block
BTry block Catch block Finally block
CCatch block Finally block
DTry block Finally block
Step-by-Step Solution
Solution:
  1. Step 1: Trace try block execution

    "Try block" is printed, then exception is thrown.
  2. Step 2: Catch and finally execution

    Catch block prints "Catch block", then finally block prints "Finally block".
  3. Final Answer:

    Try block Catch block Finally block -> Option B
  4. Quick Check:

    finally runs after catch = D [OK]
Quick Trick: finally runs after catch even if exception thrown [OK]
Common Mistakes:
MISTAKES
  • Ignoring finally block output
  • Assuming finally runs before catch
  • Missing exception thrown in try

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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