Responding to Exceptions
In Section 3.2, we examined two methods to determine when exceptions occurred: through the server-side scripting language, and for ASP 3.0, through the ASPError object. Exception handling involves more than just detecting when an exception occurs; it also involves an appropriate response. In this section, we’ll look at various ways to respond to an exception.
We’ll start with a look at displaying understandable error messages. Next, a means for notifying the technical support team of the error’s details is covered. Finally, we’ll look at ways to recover from an error. Of course, these three approaches to responding to exceptions are not mutually exclusive. That is, when an exception occurs, you can display a readable error message, notify the support team, and attempt to recover from the error.
Displaying an Understandable Error Message
Errors are inevitable . They will happen. Your code contains errors. Therefore, be ready to respond to errors gracefully. Do not trivialize exception handling, expecting your code to be error-free. The worst thing that can happen when an error occurs is premature termination of the script followed by an illegible error message. As we discussed earlier, it is vitally important to provide readable, understandable error messages for your users.
Good error messages, in my opinion, contain the following four elements:
Acknowledgement that an error occurred.
A high-level explanation of the error.
Links to other sections on ...