Window.onerror (Property)

A reference to an error event handler for this window object.


JavaScript - 1.1
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Opera - 3.0
Property/method value type:Function object
JavaScript syntax:-myWindow.onerror
-myWindow.onerror = aHandler
-onerror = aHandler
Argument list:aHandlerAn event handler function object

You can register an error handler function by assigning a function object to the window's onerror property so that when an error occurs in the JavaScript within the window, that function will be called.

This can be a useful way of trapping and completely inhibiting the display of error messages to the user. When the error handling function is called, it is passed three arguments:

The line number is the physical line number within the document, not a line number within a script, so you should be able to open the document in a text editor and go to the indicated line and identify the problem.

The only way to activate this error handling capability is to assign a function to the onerror property. There is no HTML tag attribute mechanism for defining an error handler for a window although you can associate one with the <IMG> tag with an attribute value.

You can return either true or false as a result of calling your handler:

true - Inhibit any further error processing and abort the script.

false - Hand control back to the browser to deal with the error in the normal way.

Deactivate error handling altogether by calling a function that simply returns true. To restore default error handling to the window later, assign a function handler to the property that merely returns a false value as its result without intervening in the error process in any way.


See also:Debugging - client-side, Error events, Error handler, JellyScript, onError

Property attributes: