Lejano como las mejores prácticas están preocupados, que es mejor:ArgumentException o ArgumentNullException para los parámetros de cadena?
public void SomeMethod(string str)
{
if(string.IsNullOrEmpty(str))
{
throw new ArgumentException("str cannot be null or empty.");
}
// do other stuff
}
o
public void SomeMethod(string str)
{
if(str == null)
{
throw new ArgumentNullException("str");
}
if(str == string.Empty)
{
throw new ArgumentException("str cannot be empty.");
}
// do other stuff
}
La segunda versión parece más preciso, pero también más complicado que el primero. Usualmente voy con el n. ° 1, pero pensé que verificaría si hay un argumento para el n. ° 2.
[Posible duplicar] (http://stackoverflow.com/questions/1355957/should-i-throw-argumentnullexception-if-a-string-is-blank)? Allí también sugieren otra opción: una 'StringNullOrEmptyException' personalizada. –