Freigeben über


ArgumentNullException vs ArgumentException

Both ArgumentNullException and ArgumentException have a constructor which takes two strings.  One is the name of the parameter (or argument) in question and the other is a string describing the exception.

The funny/odd/interesting thing about them is that one has the opposite order of arguments.

For ArgumentException the constructor is:

    1: public ArgumentException(
    2:     string message,
    3:     string paramName
    4: )

 

While for ArgumentNullException is it:

    1: public ArgumentNullException(
    2:     string paramName,
    3:     string message
    4: )

 

And my point is....

Well, I don't have one I just thought it was an interesting thing to point out :)

Comments

  • Anonymous
    June 02, 2008
    The funnier thing is that they both have a single-parameter string constructor meaning different things: public ArgumentException(string message); public ArgumentNullException(string paramName); I guess the argument order in 2-argument constructors for both types follows the 1-argument one, with additional arguments stuck at the end, hence the difference.

  • Anonymous
    October 14, 2008
    While you might be interested in saying what was wrong when throwing an ArgumentException, the message is pretty clear in case of ArgumentNullException. Nice detail anyway! :)