none
C# Exception handling and code maintenance RRS feed

  • Question

  • 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,

    2. Usage of those custom exceptions 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.



    SrinivasReddyVelpula


    Thursday, February 28, 2019 6:07 PM

All replies

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

    What are these 30 plus applications, becuase I am not a fan of throwing exception becuase of data validation issues?

    Thursday, February 28, 2019 6:39 PM
  • Hi SrinivasReddy Velpula,

    Thank you for posting here.

    For your question, is there something wrong for your custom exceptions? What can we do for you?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 1, 2019 5:40 AM
    Moderator