는 지금까지와 같은 모범 사례가 더있는 우려하고 있습니다 :문자열 매개 변수에 대한 ArgumentException 또는 ArgumentNullException?
public void SomeMethod(string str)
{
if(string.IsNullOrEmpty(str))
{
throw new ArgumentException("str cannot be null or empty.");
}
// do other stuff
}
또는
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
}
두 번째 버전은보다 정확한뿐만 아니라, 처음보다 더 성가신 것 같다. 나는 보통 # 1로 가고 있지만, # 2에 대한 논쟁이 있는지 확인해 볼 것입니다.
[가능한 복제본] (http://stackoverflow.com/questions/1355957/should-i-throw-argumentnullexception-if-a-string-is-blank)? 거기서 또 다른 옵션을 제안합니다 : 커스텀'StringNullOrEmptyException'. –