Section 16.2. Throwing Exceptions


16.2. Throwing Exceptions

All exceptions are either of type System.Exception or of types derived from System.Exception . Microsoft suggests that all the exceptions you use in your program derive from System.Exception , though you are also free to derive from System.ApplicationException (which was the previous recommended strategy).

The CLR System namespace includes a number of pre-defined exception types that you can use in your own programs. 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.



Learning C# 2005
Learning C# 2005: Get Started with C# 2.0 and .NET Programming (2nd Edition)
ISBN: 0596102097
EAN: 2147483647
Year: 2004
Pages: 250

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net