Window.onerror and javascript errors
I have the following code to capture errors in javascript
<script type="text/javascript"> window.onerror = function(msg, url, linenumber) { console.log('Error message: '+msg+'\nURL: '+url+'\nLine Number: '+linenumber); return true; } </script> I opened the Chrome developer console and am going to throw a ReferenceError random javascript code. Let's say:
person.run(); // person object does not exist It throws an Uncaught ReferenceError: person is not defined and prints to the console. But this is not fixed by window.onerror . Why?
An event handler for script runtime errors.
Please note that some / many error events do not cause window.onerror, you should listen to them specially.
open this link, it will be useful for you:
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror