Correct exception to throw for an unhandled switch case for an argument?

后端 未结 5 2324
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-19 22:26

NOTE: This is different than the proposed duplicates as this deals with an argument rather than a value. The behavior and applicable scenarios are essentially different.

5条回答
  •  暖寄归人
    2021-02-19 22:43

    Since you have the login in a function you can throw InvalidArgumentException.

    The exception that is raised when a parameter that is not valid is passed to a method on the referenced connection to the server.

    EDIT: A better alternative would be: ArgumentException, since InvalidArgumentException in Microsoft.SqlServer.Management.Common namespace. Something like:

    throw new ArgumentException("Unhandled value: " + value.ToString());
    

提交回复
热议问题