Is there any way to catch Javascript errors globally across the web application by writing some code in the master page?
Asked
Active
Viewed 3,356 times
0
-
1Dup: http://stackoverflow.com/questions/951791/javascript-global-error-handling and http://stackoverflow.com/questions/546990/automatic-feedback-on-javascript-error and http://stackoverflow.com/questions/205688/javascript-exception-handling and http://stackoverflow.com/questions/119432/logging-javascript-errors-on-server and – Crescent Fresh Sep 04 '09 at 13:30
-
Possible duplicate of [JavaScript global error handling](https://stackoverflow.com/questions/951791/javascript-global-error-handling) – Michael Freidgeim May 02 '19 at 21:42
2 Answers
8
You can use the onerror
event:
var oldOnError = window.onerror;
window.onerror = function()
{
alert('Something bad happened');
//Optionally...
oldOnError();
}

Greg
- 316,276
- 54
- 369
- 333
-
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 Feb 02 '10 at 19:23
-
Do you possibly know why this simple demo - http://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.) – Šime Vidas Feb 04 '11 at 20:08