18.1 Throwing Exceptions
All exceptions are either of type System.Exception
or of types derived from System.Exception. The CLR System namespace
includes a number of exception types that can be used by your
program. These exception types include ArgumentNullException,
InvalidCastException, and OverflowException, as well as many others.
You can guess their use based on their name. For example,
ArgumentNull exception is thrown when an argument to a method is null
when that is not an expected (or acceptable) value.
This chapter describes how to write your programs to catch and handle
exceptions. This chapter also shows you how to use the properties of
the Exception class to provide information to the user about what
went wrong, and it shows you how to create and use your own custom
exception types.
|