Yes, if absolutely necessary, then throw an exception. You should not * throw an exception later.
Always remember the Fail Early Principle . The concept now does not work, so you do not waste time debugging or experiencing unexpected system functions.
Alternatively, you can also throw an ArgumentException for "" and an ArgumentNullException for null. In any case, make sure you select a valid exception message.
Always a good reference article for managing exceptions: Good rules for managing thumb exceptions
Side note on what @Steve Michelotti said (because I'm a big fan of CodeContracts)
Contract.Requires<ArgumentNullException>(inputParemeter!= null, "inputparameter cannot be null"); Contract.Requires<ArgumentException>(inputParemeter!= "", "inputparameter cannot be empty string");
as an alternative
Contract.Requires<ArgumentNullException>(!string.IsNullOrEmpty(inputParemeter), "inputparameter cannot be null or empty string");
Nix 02 Sep '10 at 18:07 2010-09-02 18:07
source share