Bird
Raised Fist0

What is wrong with this code?

medium📝 Debug Q7 of Q15
C Sharp (C#) - Exception Handling
What is wrong with this code?
try {
    Console.WriteLine("Start");
} catch {
    Console.WriteLine("Error");
} finally
    Console.WriteLine("Done");
ANo error, code is valid.
Bcatch block cannot be empty.
Ctry block must have a return statement.
Dfinally block must use braces {} even for single statement.
Step-by-Step Solution
Solution:
  1. Step 1: Check finally block syntax

    finally block requires braces {} even if it has one statement.
  2. Step 2: Identify missing braces

    Missing braces cause syntax error in finally block.
  3. Final Answer:

    finally block must use braces {} even for single statement. -> Option D
  4. Quick Check:

    finally needs braces always = A [OK]
Quick Trick: Always use braces {} for finally block [OK]
Common Mistakes:
MISTAKES
  • Omitting braces in finally
  • Assuming single statement needs no braces
  • Confusing catch syntax with finally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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