I have 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 chrome developer console and going to generate ReferenceError
by random javascript code. Lets say:
person.run(); // person object does not exist
It throws Uncaught ReferenceError: person is not defined
and printed in the console. But it is not captured by window.onerror
. Why?
An event handler for runtime script errors.
Note that some/many error events do not trigger window.onerror, you have to listen for them specifically.
open this link this is use full for you:
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With