ArgumentNullException vs ArgumentException

Published 28 May 08 09:17 PM | MattManela 

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 :)

Filed under: ,

Comments

# int19h said on June 3, 2008 4:36 AM:

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.

# bja said on October 15, 2008 4:50 AM:

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! :)

Anonymous comments are disabled

About MattManela

I am a software developer at Microsoft. My blog is http://blogs.msdn.com/matt
Page view tracker