views:

282

answers:

2

Is there any way to catch Javascript errors globally across the web application by writing some code in the master page?

+7  A: 

You can use the onerror event:

var oldOnError = window.onerror;
window.onerror = function()
{
    alert('Something bad happened');

    //Optionally...
    oldOnError();
}
Greg
I have just released code to help log JavaScript errors by sending error information to the server - http://www.thecodepage.com/post/JavaScript-Error-Notifications.aspx
Gabriel McAdams