HTML and CSS Reference
In-Depth Information
Thought experiment
Micromanaging exceptions
In this thought experiment, apply what you've learned about this objective. You can
find answers to these questions in the “Answers” section at the end of this chapter.
The reason behind exception handling is, obviously, to handle exceptions. In some
cases, error conditions can be predicted and if the situation occurs, it's handled and
resolved. In this case, you might not want to simply wrap an entire code block into a
big try…catch block and have the application fail to proceed.
How would you incorporate the use of try…catch blocks into a longer JavaScript
routine with multiple points of potential error? Some errors can be corrected, and
some might not be. The correctable errors should allow the script to continue
successfully.
Objective summary
Structured error handling is provided by the JavaScript language in the form of the
try…catch…finally block.
The try…catch…finally block provides a way to try some logic, catch an error and
handle it appropriately, and finally do some clean up.
The inally block always runs whether or not an exception is thrown.
Checking for a null value before accessing any objects to ensure that they are initial-
ized is good practice.
Objective review
Which statement correctly describes the proper error handling using try…catch…finally
blocks?
A. Proper error handling allows code processing to continue and to provide appropri-
ate user feedback.
B. Proper error handling allows users to fix problems with the webpage.
1.
Proper error handling allows you to debug the application at run time.
C.
Proper error handling allows you to suppress all the bugs in your scripts.
D.
 
 
Search WWH ::




Custom Search