
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Verifying Critical Parameters
|
371
argument was passed in that was outside of a valid acceptable range. This excep-
tion is used mainly with numeric values. The
InvalidEnumArgumentException
indicates that an enumeration value was passed in that does not exist in that
enumeration type.
• Throw a
FormatException when an invalid formatting parameter is passed in as a
parameter to a method. This technique is mainly used when overriding/over-
loading methods such as
ToString that can accept formatting strings, as well as
in the parse methods on the various numeric types.
• Throw
ObjectDisposedException when a property, indexer, or method is called
on an object that has already been disposed.
• Many exceptions that derive from the
SystemException class, such as
NullReferenceException, ExecutionEngineException, StackOverflowException,
OutOfMemoryException, and IndexOutOfRangeException are thrown only by the
CLR and should not be explicitly thrown with the
throw keyword in your code.
7.1 Verifying Critical Parameters
Problem
You have a method, property, or indexer that requires the correct value or set of val-
ues to be passed in to it (e.g., cannot be
null, must be within a numeric range or a set
of numeric ranges, the enumeration value must be a valid value in the enumeration).
If an incorrect value