Name
Window.onerror: error handler invoked when a JavaScript error occurs â JavaScript 1.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
)
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 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 ...
Get JavaScript: The Definitive Guide, 5th 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.