Skip to content

Instantly share code, notes, and snippets.

@johnwargo
Last active November 8, 2016 13:45
Show Gist options
  • Save johnwargo/4a9e2b7f963c3d94e7e212fb6a7bc7bc to your computer and use it in GitHub Desktop.
Save johnwargo/4a9e2b7f963c3d94e7e212fb6a7bc7bc to your computer and use it in GitHub Desktop.
JavaScript window.onerror
window.onerror = function (msg, url, line) {
var idx = url.lastIndexOf("/");
if (idx > -1) {
url = url.substring(idx + 1);
}
//Build the message string we'll display to the user
var errStr = "ERROR in " + url + " (line #" + line + "): " + msg;
//Write the error to the console
console.error(errStr);
//Tell the user what happened
alert(errStr);
return false;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment