I was looking at a piece of code recently and noticed that someone was checking for a null parameter and throwing an ArgumentException, so I figured since ArgumentNullException inherits from ArgumentException I would just replace it with the more specific exception. Little did I know that Microsoft has a wee little bit of a problem with consistency on these.
With ArgumentExceptions it is important to have a message as well as specify which parameter is causing the trouble, so there are 2 string parameters in the ArgumentException constructor. What you might not know if you haven't switched one to the other is that they changed the order of those parameters. What I mean is that you call them like this.
throw new ArgumentException("The Message", "paramName");
throw new ArgumentNullException("paramName", "The Message");
throw new ArgumentOutOfRangeException("paramName", "The Message");
How can they possibly switch those?!?! If I am not mistaken the lower two exceptions actually inherit from the first one, so it is quite surprising that the ordering was not maintained in the second two. I need to keep an eye out for other such inconsistencies while I am working. They obviously can't easily fix it now, because too much code depends on the current ordering. I try to maintain consistence parameter ordering, but I am also not working on a framework.