The Window Object

Error Handling

The onerror property of a Window object is an event handler that is invoked when an uncaught exception propagates all the way up the call stack and an error message is about to be displayed in the browser’s JavaScript console.

    // Display error messages in a dialog box, but never more than 3 
    window.onerror = function(msg, url, line) {
        if (onerror.num++ < onerror.max) {
        alert("ERROR: " + msg + "\n" + url + ":" + line); 
        return true;
        } 
    }
    onerror.max = 3; onerror.num = 0;