I was just reading here that I shouldn’t throw ArgumentNullException from within my own source code. Why is this?
If I have a method that shouldn’t be passed null, why not check the parameter and throw if it is indeed null?
public void DoStuff(List<Int32> list) // Shouldn't be null.
{
if(list == null) // If input is null...
throw new ArgumentNullException();
...
}
Thanks.
That reference doesn’t say any such thing (I can’t find ArgumentNullException mentioned on that page). It does say not to throw a NullReferenceException, which is a completely different exception and should indeed not be thrown from your own code (you have no reason to).
I throw ArgumentNullException from my own code all the time, and so does the .NET Framework when checking parameters.