Main Page

Error Reporting

<body onload=”handleLoad()”>
<input type=”button” value=”Click Me” onclick=”handleClick()” />
When this page loads, the
function is called and an exception occurs when trying to call
a non-existent method of the window object. That thread is then exited so the
line is
never executed. When the user clicks on the button, however, the
function is still called
and an alert displays the text
Error Reporting
Because each browser has its own built-in JavaScript interpreter (including its own mechanisms for
tracking down errors while interpreting), each reports errors in different ways: Some pop up an error
message; others simply log the message to a JavaScript console. Regardless of the method used, be
aware of where this data is located on your target browsers. Browsers such as Internet Explorer, Mozilla,
Safari, and Opera each have their own unique ways of presenting this data. This section guides you to
the error message information for each of them.
Internet Explorer (Windows)
Microsoft’s flagship browser, Internet Explorer for Windows, is capable of reporting errors in a couple of
different ways. By default, Internet Explorer pops up a dialog with the error details (Figure 14-1) and
asks if you want to continue running scripts on the page. This is misleading, because clicking either Yes
or No allows other scripts to continue running.
Figure 14-1
If the browser has a debugger (such as Microsoft Script Debugger, which is discussed later in this chap-
ter), the dialog offers the option to debug the script or ignore it (Figure 14-2). Clicking Yes on this dialog
brings you into the debugger; clicking No simply closes the dialog.
Error Handling
17_579088 ch14.qxd 3/28/05 11:41 AM Page 413

JavaScript EditorFree JavaScript Editor     Ajax Editor