Complete the code to declare a custom exception class that inherits from the base exception class.
public class MyCustomException : [1] { }
The base class for all exceptions in .NET is Exception. Custom exceptions should inherit from it.
Complete the code to catch all exceptions derived from the base exception class.
try { // some code } catch ([1] ex) { Console.WriteLine(ex.Message); }
Catching Exception will catch all exceptions derived from it, which includes all standard exceptions.
Fix the error in the code by choosing the correct base class for a custom exception.
public class DataNotFoundException : [1] { public DataNotFoundException(string message) : base(message) {} }
Custom exceptions should inherit from ApplicationException or directly from Exception. Here, Exception is the best choice for custom exceptions as ApplicationException is generally not recommended for new code.
Fill both blanks to create a dictionary mapping exception types to their descriptions.
var exceptionDescriptions = new Dictionary<string, string> {
{"[1]", "Base class for all exceptions"},
{"[2]", "Base class for system exceptions"}
};Exception is the base class for all exceptions, and SystemException is the base class for system exceptions.
Fill all three blanks to create a LINQ query that selects exception names and filters system exceptions.
var systemExceptions = from ex in exceptions where ex is [1] select new { Name = ex.GetType().[2] , Type = ex.[3] };
The query filters exceptions that are SystemException or derived. It selects the exception's type name using the Name property and the exception message.