window.onerror = f...">

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?

+5
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/1205533/


All Articles