Bird
0
0

What will be the output of this C# code?

medium📝 Predict Output Q13 of 15
C Sharp (C#) - Exception Handling
What will be the output of this C# code?
try {
    Console.WriteLine("Start");
    int x = 5 / 0;
    Console.WriteLine("End");
} catch (DivideByZeroException) {
    Console.WriteLine("Error caught");
}
AStart\nError caught
BError caught
CStart\nEnd
DStart
Step-by-Step Solution
Solution:
  1. Step 1: Trace code inside try block

    "Start" prints first. Then division by zero causes an exception.
  2. Step 2: Exception triggers catch block

    Catch block runs and prints "Error caught". The line after division is skipped.
  3. Final Answer:

    Start\nError caught -> Option A
  4. Quick Check:

    Exception skips rest of try, catch prints message [OK]
Quick Trick: Exception skips rest of try, catch runs next [OK]
Common Mistakes:
MISTAKES
  • Assuming 'End' prints after exception
  • Thinking catch runs before 'Start'
  • Ignoring exception and continuing try

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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