The following exception types are used widely throughout the CLR and .NET Framework. You can throw these yourself or use them as base classes for deriving custom exception types.
Thrown when a function is called with a bogus argument. This generally indicates a program bug.
ArgumentExceptionthat’s thrown when a function argument is (unexpectedly) null.
ArgumentExceptionthat’s thrown when a (usually numeric) argument is too big or too small. For example, this is thrown when passing a negative number into a function that accepts only positive values.
Thrown when the state of an object is unsuitable for a method to successfully execute, regardless of any particular argument values. Examples include reading an unopened file or getting the next element from an enumerator where the underlying list has been modified partway through the iteration.
Thrown to indicate that a particular functionality is not supported. A good example is calling the
Addmethod on a collection for which
Thrown to indicate that a function has not yet been implemented.
Thrown when the object upon which the function is called has been disposed.
Note: In Framework 4.0, Code contracts eliminate the need for
ArgumentException(and its subclasses). Code contracts are covered in Chapter 13 of C# 4.0 in a Nutshell (O'Reilly).
Learn more about this topic from C# 4.0 Pocket Reference, 3rd Edition.
When you're programming C# 4.0 and need a little help, this tightly focused and practical book tells you exactly what you need to know -- without long introductions or bloated examples. It's ideal as a succinct quick reference or as a guide to get you rapidly up to speed if you already know Java, C++, or an earlier version of C#. Written by the authors of the acclaimed C# 4.0 in a Nutshell (O’Reilly), this book covers the entire C# 4.0 language -- without skimping on the details