Name
Window.onerror — the handler invoked when a JavaScript error occurs
Availability
JavaScript 1.1; buggy in Netscape 6/6.1
Synopsis
You register an onerror
event handler like this:
window
.onerror=handler-func
The browser invokes the handler like this:
window
.onerror(message, url, line
)
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.
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.
Description
The onerror
property of the Window object
specifies an error handler function that is invoked when a JavaScript
error occurs in code executing in that window. By default, JavaScript
displays an error dialog box when an error occurs. You can customize
error handling by providing your own onerror
event
handler.
You define an onerror
event handler for a window
by setting the onerror
property of a Window object
to an appropriate function. Note that unlike other event handlers in
JavaScript, the onerror
handler cannot be defined
in an HTML 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 ...
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.