Is there any way to catch Javascript errors globally across the web application by writing some code in the master page?
-
1Dup: stackoverflow.com/questions/951791/… and stackoverflow.com/questions/546990/… and stackoverflow.com/questions/205688/… and stackoverflow.com/questions/119432/… andCrescent Fresh– Crescent Fresh2009-09-04 13:30:03 +00:00Commented Sep 4, 2009 at 13:30
-
Possible duplicate of JavaScript global error handlingMichael Freidgeim– Michael Freidgeim2019-05-02 21:42:13 +00:00Commented May 2, 2019 at 21:42
Add a comment
|
2 Answers
You can use the onerror event:
var oldOnError = window.onerror;
window.onerror = function()
{
alert('Something bad happened');
//Optionally...
oldOnError();
}
2 Comments
Gabriel McAdams
I have just released code to help log JavaScript errors by sending error information to the server - thecodepage.com/post/JavaScript-Error-Notifications.aspx
Šime Vidas
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.)