Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The onerror property of a Window object is special. If you assign a function to this property, the function is invoked whenever a JavaScript error occurs in that window: the function you assign becomes an error handler for the window. (Note that you ought to be able to simply define a global function named onerror( ), as this should be equivalent to assigning a function to the onerror property of a Window object. Defining a global onerror( ) function does not work in IE, however.)
Three arguments are passed to an error handler when a JavaScript error occurs. The first is a message describing the error. This may be something like "missing operator in expression", "self is read-only", or "myname is not defined". The second argument is a string that contains the URL of the document containing the JavaScript code that caused the error. The third argument is the line number within the document where the error occurred. An error handler can use these arguments for any purpose; a typical error handler might display the error message to the user, log it somewhere, or force the error to be ignored. Prior to JavaScript 1.5, the onerror handler can also be used as a poor substitute for try/catch (see Chapter 6) exception handling.