0

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

2

2 Answers 2

8

You can use the onerror event:

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

    //Optionally...
    oldOnError();
}
Sign up to request clarification or add additional context in comments.

2 Comments

I have just released code to help log JavaScript errors by sending error information to the server - thecodepage.com/post/JavaScript-Error-Notifications.aspx
Do you possibly know why this simple demo - jsfiddle.net/YM9U7 - works in IE9 beta and Firefox 3.6, but doesn't work in Chrome, Safari and Opera? (By "works" I mean, the "Error!" alert is displayed.)
0

See JavaScript Exception Handling Techniques

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.