
Error Handling | 215
Error Handling
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
For the code in Example 10-4 to work, you need to provide valid email addresses
for the To and From properties of the MailMessage object instance.
If an unhandled exception occurs in a custom error page, no further redirect will
occur, so the user will see a blank page. This situation makes it extremely impor-
tant for you to ensure that no unhandled exceptions occur in custom error pages.
For example, it might be a good idea to wrap the call to SmtpMail.Send in
Example 10-4 in a
Try...Catch block) to handle potential problems with
connecting to the specified SMTP server. For more information about using the
Try...Catch block, see “Structured Exception Handling,” later in this chapter.
The advantage of using custom error pages is that it allows you to handle a lot of
errors from a single location (or a small number of locations). The disadvantage is
that there’s not much you can do to handle the error, other than display a helpful
message and notify someone that an error occurred. The reason for this is that you
don’t have access to the actual exception object in a custom error page, which
means you can neither display information about the specific exception nor take
steps to handle it.
Page_Error and Application_Error
Another technique for error handling ...