C#.NET — Which statements about exception handling are correct? 1) If our program does not catch an exception then the .NET CLR catches it. 2) It is possible to create user-defined exceptions. 3) All types of exceptions can be caught using the Exception class. 4) CLRExceptions is the base class for all exception classes. 5) For every try block there must be a corresponding finally block.

Difficulty: Easy

Correct Answer: 1, 2 and 3 only

Explanation:


Introduction / Context:
Solid exception handling requires knowing the runtime's behavior, the hierarchy of exception classes, and the structure of try/catch/finally. This question asks you to validate several common claims.



Given Data / Assumptions:

  • We are working with managed .NET code.
  • Exception is the root of the exception hierarchy.
  • Finally blocks are optional companions to try blocks.


Concept / Approach:
(1) True: Uncaught exceptions are handled by the CLR, which reports and terminates the process. (2) True: You can define custom exceptions by deriving from System.Exception. (3) True: A catch (Exception) handler can catch any exception type unless filtering or rethrow occurs. (4) False: The base class is System.Exception, not “CLRExceptions”. (5) False: try can pair with catch alone or finally alone; a finally block is not mandatory for every try.



Step-by-Step Solution:

Mark 1 true → CLR catches unhandled exceptions.Mark 2 true → user-defined exceptions derive from Exception.Mark 3 true → Exception catch is a universal catch.Mark 4 false → wrong base class name.Mark 5 false → try/catch is valid without finally, and try/finally is valid without catch.


Verification / Alternative check:
Create MyException : Exception and throw it; catch (Exception) will handle it. Write try { } finally { } without catch; it compiles and runs.



Why Other Options Are Wrong:

  • C and D include false statements 4 and/or 5.
  • E is wrong because statements 1–3 are correct.
  • A omits the also-true statement 3.


Common Pitfalls:
Believing finally is mandatory or misnaming the root exception type. Also, catching Exception broadly should be used judiciously.



Final Answer:
1, 2 and 3 only

More Questions from Exception Handling

Discussion & Comments

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