jeudi 28 février 2019

C# Exception handling and code maintenance [on hold]

I have a validator class in this, I will be validating(Empty or Not and duplicate) the data type values like string, int, GUID, List etc.

For this, I am throwing Argument null exception in case of value null or empty and custom exceptions for UserNotFound, duplicate, a record not found etc.

Previously I used to throw the exception directly like below,

 **throw new ArgumentNullException(paramName);**

But, I feel it be huge change If the custom exception class name changes or any modifications related to that.

Because I will be using those custom and predefined exceptions in 30+ applications.

Now I restructured it in below manner,

1. A class which throws all custom exceptions,

enter image description here

2. Usage of those custom exceptions here,

enter image description here

Can anyone confirm whether it is okay or not?

If it is okay, what type of benefits I will get from this I was unable to understand.

Let us know your thoughts on this.

Aucun commentaire:

Enregistrer un commentaire