Bird
0
0

Identify the error in this C# code snippet:

medium📝 Debug Q14 of 15
C Sharp (C#) - Exception Handling
Identify the error in this C# code snippet:
try {
    Console.WriteLine("Hello");
} finally {
    Console.WriteLine("Cleanup");
} catch (Exception ex) {
    Console.WriteLine("Error");
}
AThe <code>catch</code> block must come after <code>finally</code>
BNo error, code is correct
CYou cannot use <code>finally</code> without <code>catch</code>
DThe <code>finally</code> block must come after <code>catch</code>
Step-by-Step Solution
Solution:
  1. Step 1: Check block order rules

    In C#, the finally block must come after all catch blocks.
  2. Step 2: Identify incorrect order

    The code places finally before catch, which is invalid syntax.
  3. Final Answer:

    The finally block must come after catch -> Option D
  4. Quick Check:

    finally after catch [OK]
Quick Trick: Remember: catch blocks come before finally [OK]
Common Mistakes:
MISTAKES
  • Placing finally before catch
  • Thinking finally can be before catch
  • Confusing order of blocks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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