Why no ArgumentEmptyException in .NET ?

Posted by Andrei Rinea on Stack Overflow See other posts from Stack Overflow or by Andrei Rinea
Published on 2010-06-01T19:49:54Z Indexed on 2010/06/01 19:53 UTC
Read the original article Hit count: 277

Filed under:
|
|
|
|

I am beginning to think I am doing something wrong. I mean they did place System.String.IsNullOrWhitespace finally but no ArgumentEmptyException class.

        public FilterItem(string name, IEnumerable<string> extensions)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }
            if (extensions == null)
            {
                throw new ArgumentNullException("extensions");
            }
            if (extensions.Count() == 0)
            {
                throw new ArgumentOutOfRangeException("extensions");
            }

            this.Name = name;
            this.Extensions = extensions;
        }

throwing an ArgumentOutOfRangeException feels unnatural. Also an instance of ArgumentException is too general in my opinion.

It's easy to me to create a new exception class call it this way and have it over with. What bugs me is that it's not in the BCL/FCL and I am beginning to think there's a good reason not to have it.

Should there be one?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about exception