Recall & Review
beginner
What is a custom exception class in C#?A custom exception class is a user-defined class that inherits from <code>Exception</code> or its subclasses to represent specific error conditions in your program.Click to reveal answer
beginner
How do you define a basic custom exception class in C#?You create a class that inherits from <code>Exception</code> and provide constructors, for example:<br><pre>public class MyException : Exception { public MyException(string message) : base(message) {} }</pre>Click to reveal answer
intermediate
Why should you create custom exception classes instead of using general exceptions?
Custom exceptions help you clearly identify and handle specific error cases, making your code easier to read, debug, and maintain.
Click to reveal answer
beginner
Which base class do all custom exceptions in C# usually inherit from?They usually inherit from the <code>Exception</code> class, which is the base class for all exceptions in C#.Click to reveal answer
beginner
What is the purpose of calling
base(message) in a custom exception constructor?It passes the error message to the base <code>Exception</code> class so that the message can be accessed later when the exception is caught.Click to reveal answer
Which keyword is used to create a custom exception class in C#?
✗ Incorrect
You use the
class keyword to define a new class that inherits from Exception.What should a custom exception class inherit from?
✗ Incorrect
Custom exceptions should inherit from
System.Exception to behave like standard exceptions.Why do you call
base(message) in a custom exception constructor?✗ Incorrect
Calling
base(message) passes the message to the base Exception class for proper error handling.Which of these is a benefit of using custom exceptions?
✗ Incorrect
Custom exceptions help you identify and handle specific errors clearly.
Which constructor is commonly included in a custom exception class?
✗ Incorrect
A constructor that takes a string message allows you to pass an error description when throwing the exception.
Explain how to create a custom exception class in C# and why it is useful.
Think about class inheritance and error clarity.
You got /4 concepts.
Describe the role of the base Exception class when defining custom exceptions.
Base class is the foundation for all exceptions.
You got /4 concepts.