Bird
0
0

Consider this code:

hard🚀 Application Q15 of 15
C Sharp (C#) - Exception Handling
Consider this code:
try {
    Console.WriteLine("A");
    try {
        int y = int.Parse("abc");
    } catch (FormatException) {
        Console.WriteLine("Format error");
    }
    Console.WriteLine("B");
} catch (Exception) {
    Console.WriteLine("General error");
}

What will be the output?
AA\nGeneral error\nB
BA\nFormat error\nB
CFormat error\nB
DA\nB
Step-by-Step Solution
Solution:
  1. Step 1: Trace outer try block

    Prints "A" first, then enters inner try block.
  2. Step 2: Inner try-catch handles FormatException

    Parsing "abc" causes FormatException, caught by inner catch which prints "Format error".
  3. Step 3: Continue outer try after inner catch

    After inner catch, prints "B". Outer catch is not triggered.
  4. Final Answer:

    A\nFormat error\nB -> Option B
  5. Quick Check:

    Inner catch handles error, outer continues [OK]
Quick Trick: Inner catch handles error, outer try continues after [OK]
Common Mistakes:
MISTAKES
  • Assuming outer catch runs instead of inner
  • Thinking code stops after inner exception
  • Missing that 'B' prints after inner catch

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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