C#.NET — Object-Oriented way to handle run-time errors: choose the correct mechanism.

Difficulty: Easy

Correct Answer: Exceptions

Explanation:

Introduction / Context:Object-Oriented languages, including C#, use a structured mechanism for error handling that integrates with control flow and type hierarchies.

Given Data / Assumptions:

  • We compare legacy or C-style techniques with OO approaches.

Concept / Approach:Exceptions provide a type-safe, structured way to signal and handle run-time errors using try/catch/finally blocks, enabling separation of error detection and error handling logic.

Step-by-Step Solution:

Identify the OO mechanism in C#: exceptions with try/catch/finally. Other options represent non-OO or language-specific patterns (VB OnError, C setjmp/longjmp, ad-hoc error codes).

Verification / Alternative check:In C#, throwing and catching Exception-derived types is the standard approach endorsed by the framework.

Why Other Options Are Wrong:They are not idiomatic in C# or are legacy/non-OO techniques.

Common Pitfalls:Overusing exceptions for normal control flow or swallowing exceptions without logging.

Final Answer:Exceptions

More Questions from Exception Handling

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion