Bird
0
0

Identify the error in this custom exception class declaration:

medium📝 Debug Q14 of 15
C Sharp (C#) - Exception Handling
Identify the error in this custom exception class declaration:
class MyError : Exception {
public MyError(string msg) {
base(msg);
}
}
AThe class must not inherit from Exception
BThe constructor should be named differently from the class
CThe constructor should call base(msg) using a colon, not inside the body
DThe base class Exception does not accept a string parameter
Step-by-Step Solution
Solution:
  1. Step 1: Check constructor syntax for base call

    In C#, calling the base class constructor must be done with a colon after the constructor signature, not inside the body.
  2. Step 2: Identify correct syntax

    The correct syntax is public MyError(string msg) : base(msg) {}, not calling base(msg); inside the constructor body.
  3. Final Answer:

    The constructor should call base(msg) using a colon, not inside the body -> Option C
  4. Quick Check:

    Base constructor call uses colon syntax = B [OK]
Quick Trick: Call base constructor with colon, not inside method body [OK]
Common Mistakes:
MISTAKES
  • Calling base constructor inside body instead of colon
  • Not inheriting from Exception
  • Misnaming constructor

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Sharp (C#) Quizzes