You have to return false
at the end of the error handler to let the default error handler (which logs to the console) run.
window.onerror = function myErrorHandler(errorMsg, url, lineNumber) {
//Do some of your ajax requests or whatever
return false;
}
Out of MDN:
When the function returns true, this prevents the firing of the default event handler.
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror