Section 25.304. Window.onerror: error handler invoked when a JavaScript error occurs


25.304. Window.onerror: error handler invoked when a JavaScript error occurs

JavaScript 1.1:

25.304.1. Synopsis

You register an onerror handler like this:

 window.onerror=handler-func 

The browser invokes the handler like this:

 window.onerror(message, url, line) 

25.304.1.1. Arguments

message

A string that specifies the error message for the error that occurred.


url

A string that specifies the URL of the document in which the error occurred.


line

A number that specifies the line number at which the error occurred.

25.304.1.2. Returns

true if the handler has handled the error and JavaScript should take no further action; false if JavaScript should post the default error message dialog box for this error.

25.304.2. Description

The onerror property of the Window object specifies an error-handler function that is invoked when a JavaScript error occurs and is not caught with a catch statement. You can customize error handling by providing your own onerror error handler.

You define an onerror handler for a window by setting the onerror property of a Window object to an appropriate function. Note that onerror is an error handler and differs from event handlers. In particular, an error handler cannot be defined with an onerror attribute on the <body> tag.

When the onerror handler is invoked, it is passed three arguments: a string specifying the error message, a string specifying the URL of the document in which the error occurred, and a number that specifies the line number at which the error occurred. An error handling function may do anything it wants with these arguments: it may display its own error dialog box or log the error in some way, for example. When the error-handling function is done, it should return true if it has completely handled the error and wants the browser to take no further action, or false if it has merely noted or logged the error in some fashion and still wants the browser to handle the error.




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net