From MSDN, code analysis warning CA1032:
Exception types must implement the following constructors:
This is a warning, not a requirement. It's basically principle of least surprise. Providing all 4 makes it easier for people used to "regular" C# exceptions to use yours. If you have a good reason to ignore the guideline, do so. But it will break certain usage scenarios, and make your class a little less intuitive.
You have gotten some good answers. I just want to add that providing these extra constructors does not necessarily require a lot of coding. Since they are already implemented in the base class, you can simply let that one do the work:
public class MyCustomException : Exception { public MyCustomException() : base() { } public MyCustomException(string message) : base(message) { } public MyCustomException(string message, Exception innerException) : base(message, innerException) { } // and so on... }
So you will only need to implement code where the behaviour of your exception deviates from that of the base class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With