0
0
C Sharp (C#)programming~5 mins

Exception hierarchy in .NET in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the base class for all exceptions in .NET?
The base class for all exceptions in .NET is <strong>System.Exception</strong>. All other exceptions inherit from this class.
Click to reveal answer
intermediate
What is the difference between System.Exception and System.SystemException?
<code>System.Exception</code> is the root class for all exceptions. <code>System.SystemException</code> is a subclass used for exceptions thrown by the runtime, like <code>NullReferenceException</code> or <code>IndexOutOfRangeException</code>.
Click to reveal answer
intermediate
Name two common subclasses of System.SystemException.
Two common subclasses of System.SystemException are NullReferenceException and IndexOutOfRangeException. These are used for runtime errors.
Click to reveal answer
beginner
What is the purpose of System.IO.IOException in the exception hierarchy?
<code>System.IO.IOException</code> is a subclass of <code>System.Exception</code> that handles errors related to input/output operations, such as file access problems.
Click to reveal answer
beginner
Why should you catch specific exceptions instead of catching System.Exception directly?
Catching specific exceptions helps you handle different error types properly and avoid hiding unexpected errors. Catching System.Exception can make debugging harder and may catch exceptions you don't intend to handle.
Click to reveal answer
Which class is the direct parent of System.NullReferenceException?
ASystem.SystemException
BSystem.ApplicationException
CSystem.Exception
DSystem.IO.IOException
Which exception class should you use for errors caused by invalid arguments?
ASystem.ArgumentException
BSystem.IO.IOException
CSystem.NullReferenceException
DSystem.InvalidOperationException
What is the root class of all exceptions in .NET?
ASystem.SystemException
BSystem.Exception
CSystem.ApplicationException
DSystem.Object
Which exception type is best for handling file read/write errors?
ASystem.InvalidOperationException
BSystem.NullReferenceException
CSystem.ArgumentException
DSystem.IO.IOException
Why is catching System.Exception generally discouraged?
AIt catches too few exceptions
BIt only catches runtime exceptions
CIt can hide unexpected errors and make debugging harder
DIt is deprecated in .NET
Explain the main branches of the exception hierarchy in .NET and their purposes.
Think about runtime vs application exceptions.
You got /4 concepts.
    Describe why it is important to catch specific exceptions rather than the base Exception class.
    Consider what happens if you catch everything at once.
    You got /4 concepts.