AJAX: How to Catch Evil Errors with OnError

Over on the Ajaxian blog they mention some evil code that was squelching exceptions (i.e. it was doing a try/catch and then doing nothing in the catch). I've run into this issue myself, having things fail mysteriously. One way to catch these kinds of problems is to use window.onerror (another reference):

var errorHandler = function(msg, url, linenumber) {
alert("Error: " + msg + " for " + url + " at " + linenumber);
};

window.onerror = errorHandler;
Now, whenever an error occurs, the error handler will get an error message, the URL that is the source of the error, and a line number! Window.onerror works in Firefox and IE, but I believe that it fails in Safari (continuing my general frustration with Safari as a browser).

Comments

Thogek said…
As far as I can tell, this is still the case, and still frustrating...

Any word on whether it might someday change?