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

Exception hierarchy in .NET in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a custom exception class that inherits from the base exception class.

C Sharp (C#)
public class MyCustomException : [1] {
}
Drag options to blanks, or click blank then click option'
AException
BSystemException
CApplicationException
DBaseException
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from SystemException instead of Exception
Using a non-existent base class like BaseException
2fill in blank
medium

Complete the code to catch all exceptions derived from the base exception class.

C Sharp (C#)
try {
    // some code
} catch ([1] ex) {
    Console.WriteLine(ex.Message);
}
Drag options to blanks, or click blank then click option'
ASystemException
BBaseException
CApplicationException
DException
Attempts:
3 left
💡 Hint
Common Mistakes
Catching SystemException only catches system exceptions, not all exceptions.
Using a non-existent class like BaseException.
3fill in blank
hard

Fix the error in the code by choosing the correct base class for a custom exception.

C Sharp (C#)
public class DataNotFoundException : [1] {
    public DataNotFoundException(string message) : base(message) {}
}
Drag options to blanks, or click blank then click option'
AApplicationException
BSystemException
CException
DErrorException
Attempts:
3 left
💡 Hint
Common Mistakes
Using SystemException which is meant for system exceptions.
Using a non-existent class like ErrorException.
4fill in blank
hard

Fill both blanks to create a dictionary mapping exception types to their descriptions.

C Sharp (C#)
var exceptionDescriptions = new Dictionary<string, string> {
    {"[1]", "Base class for all exceptions"},
    {"[2]", "Base class for system exceptions"}
};
Drag options to blanks, or click blank then click option'
AException
BSystemException
CApplicationException
DBaseException
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing ApplicationException with SystemException.
Using a non-existent class like BaseException.
5fill in blank
hard

Fill all three blanks to create a LINQ query that selects exception names and filters system exceptions.

C Sharp (C#)
var systemExceptions = from ex in exceptions
                       where ex is [1]
                       select new { Name = ex.GetType().[2] , Type = ex.[3] };
Drag options to blanks, or click blank then click option'
ASystemException
BName
CGetType
DMessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetType() instead of the Name property for the type name.
Using the wrong property for the message.