
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
364
Chapter 7
CHAPTER 7
Exception Handling
7.0 Introduction
This chapter contains recipes covering the exception-handling mechanism, includ-
ing the
try, catch, and finally blocks. Along with these recipes are others covering
the mechanisms used to throw exceptions manually from within your code. The final
types of recipes include those dealing with the
Exception classes and their uses, as
well as subclassing them to create new types of exceptions.
Often the design and implementation of exception handling is performed later in the
development cycle. But with the power and complexities of C# exception handling,
you need to plan and even implement your exception-handling scheme much earlier.
Doing so will increase the reliability and robustness of your code while minimizing the
impact of adding exception handling after most or all of the application is coded.
Exception handling in C# is very flexible. It allows you to choose a fine- or coarse-
grained approach to error handling and any level between. This means that you can
add exception handling around any individual line of code (the fine-grained
approach) or around a method that calls many other methods (the coarse-grained
approach), or you can use a mix of the two, with mainly a coarse-grained approach
and a more fine-grained approach