There are many exceptions to choose
from in the FCL. You need an easily accessible list of these
exceptions that indicates when and where to use them. By throwing
exceptions in a consistent manner (e.g., throwing an
IndexOutOfRangeException
when an array index is
greater than the length of the array), you and others on your team
will be able to debug problems more easily.
Use the list of exceptions and their definitions in Table 5-1 to determine which exception to employ when throwing or catching exceptions.
Table 5-1. The built-in exception types
Exception name |
Derives from |
Description |
---|---|---|
|
Use this class as the base class to user-defined exceptions; a more derived exception should be thrown. | |
|
Thrown when a parameter value for a method is | |
|
Thrown when a parameter value for a method is out of the range of expected values. | |
|
Thrown when an incompatible data type is assigned to an element in an array. | |
|
Thrown when an unknown | |
|
Thrown when an invalid configuration setting is encountered. | |
|
Thrown when a custom attribute format is incorrect. | |
|
Thrown when a file or directory cannot be found. | |
|
Base class of all exceptions; you should always throw a more derived exception. | |
|
Thrown when an invalid format parameter is passed to a method. | |
|
Thrown when you attempt to access an array element with an index value outside the valid range for that array. | |
|
Thrown during software installation when an error is encountered during uninstall, committing of data, or rolling back of data. | |
|
Thrown when an invalid enumeration value is passed to a method. | |
|
Thrown when a method is called while the object it resides in is in a state that makes it illegal to call this method. | |
|
Thrown when a general I/O exception occurs; you should throw a more derived exception. | |
|
Thrown when a general error occurs while using a class member; you should throw a more derived exception. | |
|
Thrown when a general error occurs while using a method member. | |
|
Thrown when a double or single data type is expected to have a finite number and instead it contains NaN, +infinity, or - infinity. | |
|
Thrown when a member is accessed that is not yet implemented. | |
|
Thrown when a member is accessed that is not yet supported. | |
|
Thrown when a reference set to | |
|
Thrown when a disposed object is accessed. | |
|
Thrown when a service times out. | |
|
Thrown when a warning message needs to be displayed. This exception does not imply a serious failure of the application or system. | |
|
Thrown when a pluggable protocol causes an error. | |
|
Thrown due to a general error in the XML. |