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

Custom exception classes 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 named MyException.

C Sharp (C#)
public class MyException : [1] { }
Drag options to blanks, or click blank then click option'
AException
BError
CBaseException
DSystemException
Attempts:
3 left
💡 Hint
Common Mistakes
Using Error or BaseException which are not valid base classes in C#.
Forgetting to inherit from any class.
2fill in blank
medium

Complete the constructor to call the base Exception constructor with a message.

C Sharp (C#)
public class MyException : Exception {
    public MyException(string message) : [1](message) { }
}
Drag options to blanks, or click blank then click option'
Athis
Bsuper
Cbase
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using this instead of base, which calls the current class constructor.
Using super or parent which are not C# keywords.
3fill in blank
hard

Fix the error in the custom exception class by adding the missing constructor for serialization.

C Sharp (C#)
using System;
using System.Runtime.Serialization;

[Serializable]
public class MyException : Exception {
    public MyException(string message) : base(message) { }
    protected MyException(SerializationInfo info, [1] context) : base(info, context) { }
}
Drag options to blanks, or click blank then click option'
ASerializationContext
BContext
CStreamContext
DStreamingContext
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter types like SerializationContext or Context.
Omitting the protected constructor needed for serialization.
4fill in blank
hard

Fill both blanks to complete the custom exception class with a default constructor and a message constructor.

C Sharp (C#)
public class MyException : Exception {
    public MyException() : [1]() { }
    public MyException(string message) : [2](message) { }
}
Drag options to blanks, or click blank then click option'
Abase
Bthis
Csuper
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using this instead of base, which calls another constructor in the same class.
Using super or parent which are not valid in C#.
5fill in blank
hard

Fill all three blanks to complete the custom exception class with default, message, and serialization constructors.

C Sharp (C#)
using System;
using System.Runtime.Serialization;

[Serializable]
public class MyException : Exception {
    public MyException() : [1]() { }
    public MyException(string message) : [2](message) { }
    protected MyException(SerializationInfo info, [3] context) : base(info, context) { }
}
Drag options to blanks, or click blank then click option'
Abase
Bthis
CStreamingContext
DSerializationContext
Attempts:
3 left
💡 Hint
Common Mistakes
Using this instead of base for constructors.
Using wrong parameter type for serialization constructor.