Bird
0
0

What is the issue with the following C# code?

medium📝 Debug Q6 of 15
C Sharp (C#) - Exception Handling
What is the issue with the following C# code?
try {
    Console.WriteLine("Processing");
} catch (Exception ex) {
    Console.WriteLine("Error occurred");
} finally {
    Console.WriteLine("Finished");
} catch {
    Console.WriteLine("Another catch");
}
AMultiple catch blocks after finally are not allowed
Bfinally block cannot contain Console.WriteLine statements
Ctry block must have at least two catch blocks
Dcatch blocks must come after finally block
Step-by-Step Solution
Solution:
  1. Step 1: Review try-catch-finally structure

    In C#, the finally block must come after all catch blocks and only one finally block is allowed.
  2. Step 2: Identify the error

    The code has a catch block after the finally block, which is invalid syntax.
  3. Final Answer:

    Multiple catch blocks after finally are not allowed -> Option A
  4. Quick Check:

    catch blocks must precede finally [OK]
Quick Trick: catch blocks must come before finally [OK]
Common Mistakes:
MISTAKES
  • Placing catch after finally
  • Multiple finally blocks
  • Empty try block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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