O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

ArgumentNullException

ArgumentNullException is the little, more specialized, brother of ArgumentException and is used to signal an unexpected null reference supplied for a parameter. Again, it pinpoints a missing null check in your code and should be treated seriously. Ask yourself how the null reference got to that very place in the code to begin with.

Extinguish the evil null reference as close to its root as possible (for example, an entry point to the component you’re developing). And the way to do it is by throwing exactly this exception. Constructors typically used for this purpose include the following:

public ArgumentNullException(string paramName);public ArgumentNullException(string paramName, string message); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required