Skip to content

Instantly share code, notes, and snippets.

@carlcraig
Last active August 29, 2015 14:14
Show Gist options
  • Save carlcraig/37620e942cdf35b3d658 to your computer and use it in GitHub Desktop.
Save carlcraig/37620e942cdf35b3d658 to your computer and use it in GitHub Desktop.
JS Error Catching
(function ErrorHandler(errorElement) {
var self = this;
self.errorcount = 0;
self.onerror = onerror;
self.originalOnerror = window.onerror;
self.revertErrorHandler = revertErrorHandler;
window.onerror = self.onerror;
window.onload = onload;
function onload() {
revertErrorHandler();
if (self.errorcount > 0) {
document.getElementById(errorElement).style.display = 'block'
}
}
function onerror(msg, url, line, col, error) {
self.errorcount++;
return false;
}
function revertErrorHandler() {
window.onerror = self.originalOnerror;
}
})('unsupported-browser');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment