HTML and CSS Reference
That a program can deal with errors and unknown conditions is critical in any software
deal with these situations.
Good defensive programming also includes checking for null values, where appropriate, to
prevent errors. In addition to handling errors, code can raise custom errors as needed to send
error information back to a running program from custom objects or libraries.
This objective covers using the try…catch…finally construct, evaluating for the null
condition, and raising custom errors.
This objective covers how to:
■ Implement try-catch-finally blocks, including setting and responding to error
codes and throwing exceptions
■ Check for null values
The try…catch…finally construct handles exceptions that occur during program processing. It
enables you to see what kind of error occurred and to do what's appropriate with it. If try…
catch…finally isn't implemented in the program, the errors would be treated as unhandled
and could cause the browser to crash or, at a minimum, display many annoying message
boxes to users, such as this one shown in Figure 2-3 that is caused from this code:
FIGURE 2-3 An unhandled exception error dialog box