
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Identifying Exceptions and Their Usage
|
375
7.3 Identifying Exceptions and Their Usage
Problem
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
ArgumentNullException when an
an argument is null), you and others on your team will be able to debug problems
more easily.
Solution
Use the list of exceptions and their definitions in Table 7-1 to determine which
exception to employ when throwing or catching exceptions.
Discussion
Table 7-1. The built-in exception types
Exception name Derives from Description
System.ApplicationException Exception Thrown when a nonfatal application error
occurs.
System.ArgumentNullException ArgumentException Thrown when a parameter value for a method
is
null and null is not allowed.
System.
ArgumentOutOfRangeException
ArgumentException Thrown when aparametervalueforamethod
is out of the range of expected values.
System.
ArrayTypeMismatchException
SystemException Thrown when an incompatible data type is
assigned to an element in an array.
System.Runtime.
InteropServices.COMException
ExternalException Thrown when an unknown HRESULT is
returned from a COM object.
System.Configuration.
ConfigurationException
SystemException ...