JavaScript onerror Event

Any error that is not handled by the try-catch statement causes the onerror event to fire on the window object.

The onerror event doest not create an event object, it is called by the object of the window that has the errors.

The onerror event accepts the three arguments which are:

Here is the general form to use onerror event in JavaScript to display the error message.

window.onerror = function(errormessage, url, line)
{
   alert(errormessage);
}

JavaScript Online Test


« Previous Tutorial Next Tutorial »