The following table breaks down the standard exceptions provided by the runtime and the conditions they should be subclassed/thrown.
Exception Type | Base Type | Description | Example |
---|---|---|---|
Exception | Object | Base class for all Exceptions. | None (use a subclass of this exception). |
SystemException | Excetion | Base class for all runtime generated errors. | None (use a subclass of this exception). |
CoreException | SystemException | Base class for all fetal runtime errors | None (use a subclass of this exception). |
IndexOutOfRangeException | CoreException | Thrown only by the runtime when an array is indexed improperly. | Indexing an array outside of it’s valid range:
arr[arr.Length+1] |
NullReferenceException | CoreException | Thrown only by the runtime a null object is referenced. | object o = null;
o.ToString(); |
InvalidOperationException | SystemException | Thrown by methods when in an invalid state. | Calling Enumerator.GetNext() after removing an Item from the underlying collection. |
ArgumentException | SystemException | Base class for all Argument Exceptions. Subclasses of this exception should be thrown where applicable. | None (use a subclass of this exception). |
ArgumentNullException | ArgumentException | Thrown by methods which do not allow an argument to be null. | String s = null;
”foo”.IndexOf (s); |
ArgumentOutOfRangeException | ArgumentException | Thrown by a methods which verify arguments are in a given range. | String s = “foo”;
s.Chars[9]; |
InteropException | SystemException | Base class for exceptions that occur or are targeted at environments outside of the runtime. | None (use a subclass of this exception). |
ComException | InteropException | Exception encapsulating Com classic Hresult information. | Used in Com interop. |
SEHException | InteropException | Exception encapsulating Win32 structured Exception Handling information | Used in unmanaged code interop. |