Skip to main content

Posts

Showing posts with the label exception constructors

Constructors for user defined Exceptions in C#

The following are the rules that are to be adhered to when creating any custom user  defined exception. 1. Follow the Naming convention so that the self-explanatory name of the exception ends with Exception like: ArgumentNullException. 2. The following constructors should be defined public NewException() public NewException(string message) public NewException(string message, Exception exception) protected or private NewException(SerializationInfo serializationInfo, StreamingContext streamingContext) These ensure that the created Exception satisfies the default rules of User Defined Exceptions. [Also Satisfies FxCop Validation] -- Saravanan