Suppose I have some function that will output an alert() :
var foo(err){ alert(err) } And let's say somewhere in the code, an error occurs with an undefined variable and an attempt to access its property:
Uncaught TypeError: Cannot read property 'x' of undefined
I can see this message in the console, but how to write a handler, or eventListener for the console? those. I want to pass an error message in the console to my foo() function, and I don’t have to wrap the required part of the code with conditions or use try catch .