Bird
Raised Fist0

Which base class should a custom exception class in C# usually inherit from?

easy🧠 Conceptual Q2 of Q15
C Sharp (C#) - Exception Handling
Which base class should a custom exception class in C# usually inherit from?
ASystem.Collections
BSystem.Object
CSystem.String
DSystem.Exception
Step-by-Step Solution
Solution:
  1. Step 1: Identify the base class for exceptions

    In C#, all exceptions inherit from System.Exception, which provides the core exception functionality.
  2. Step 2: Evaluate other options

    System.Object is the root of all classes but not specific to exceptions. System.String and System.Collections are unrelated to exceptions.
  3. Final Answer:

    System.Exception -> Option D
  4. Quick Check:

    Custom exception base = System.Exception [OK]
Quick Trick: Always inherit custom exceptions from System.Exception [OK]
Common Mistakes:
MISTAKES
  • Inheriting from System.Object directly
  • Using unrelated classes like System.String
  • Forgetting to inherit from any class

Want More Practice?

15+ quiz questions · All difficulty levels · Free

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