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

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());

I'd throw the InvalidEnumArgumentException as it will give more detailed information in this case, you are checking on an enum


ArgumentException looks the most correct to me in this instance (though is not defined in the BCL).

There is a specialized exception for enum arguments - InvalidEnumArgumentException:

The exception thrown when using invalid arguments that are enumerators.

An alternative is ArgumentOutOfRangeException:

The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method.

The logic for using these is that the passed in argument (value) is not valid as far as someFunc is concerned.

Tags:

C#

.Net

Exception