Difficulty: Easy
Correct Answer: 2 and 5 only
Explanation:
Introduction / Context:This question checks core knowledge of C#.NET exception handling, especially the purpose and behavior of the finally block. Understanding which statements are universally true helps you write reliable cleanup logic and avoid misconceptions about abrupt termination.
Given Data / Assumptions:
Concept / Approach:In standard execution, finally runs regardless of whether an exception is thrown or caught. It is the recommended place for deterministic cleanup, such as disposing resources or closing handles. A single try block may be followed by zero or more catch blocks and at most one finally block.
Step-by-Step Solution:
Evaluate (1): False. Exceptions can be caught, allowing recovery. Abrupt termination happens only if the exception is unhandled or the process is explicitly terminated. Evaluate (2): True. finally executes whether or not an exception occurs (barring catastrophic termination). Evaluate (3): False. Per try, you can have many catch blocks but only one finally block. Evaluate (4): Wording is imprecise; finally is associated with try and written after try/catch blocks, not inside the try’s braces. The item is poorly phrased for a “correct” fact compared with (2) and (5). Evaluate (5): True. finally is used for cleanup (closing files/DB connections/sockets).Verification / Alternative check:Write sample code with try { … } catch { … } finally { Console.WriteLine("F"); }. You will observe the finally output in both success and failure cases.
Why Other Options Are Wrong:Option A claims inevitable termination. Option D assumes multiple finally blocks per try. Option E ignores two clearly correct statements.
Common Pitfalls:Believing finally will run even after process termination; misunderstanding that only one finally is allowed per try.
Final Answer:2 and 5 only
Discussion & Comments