Suppose something like
<script src="http://mydomain.tld/buggy.js" type="text/javascript"></script>
I get in my console
Uncaught ReferenceError: foo is not defined
I can't tell the developers to wrap the code in try/catch, but nonetheless would like handle that error on every client. I saw that overriding/extending ReferenceError
is not possible.
I also tried the following (from here):
function handleError(evt) {
if (evt.message) { // Chrome sometimes provides this
alert("error: "+evt.message +" at linenumber: "+evt.lineno+" of file: "+evt.filename);
} else {
alert("error: "+evt.type+" from element: "+(evt.srcElement || evt.target));
}
}
window.addEventListener("error", handleError, true);
Which pops up a message almost like I'd want to "error: Script error. at linenumer:0 of file:
Can I make it include the original error message (Uncaught ReferenceError: foo is not defined
)?