
220
|
Chapter 10: Error Handling, Debugging, and Tracing
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
As you can see from the examples in this section, of the available exception-
handling techniques, structured exception handling is likely to require the most
code to implement. However, it also provides you with the ability to handle the
exception transparently to the user in cases when it is possible to recover from the
exception. For example, you could modify the code in Example 10-6 to test
whether the exception was related to the attempt to open the connection and, if
so, retry the connection a predefined number of times. This way, if the exception
is the result of a temporary network problem, the exception handling code can
potentially handle this problem without the user ever being aware that a problem
exists (apart from the slight delay in connecting).
Debugging
Debugging is the process of locating and eliminating errors in an application.
Each error falls into one of three categories:
Syntax errors
These errors result from writing code that violates the rules of the language. A
good example of a syntax error is failing to end a statement in C# with a
semicolon. Syntax errors are typically caught and reported by the compiler,
and thus are the easiest to debug.
Crashing semantic errors
These errors result when code that is syntactically ...