sophisticated error handling
If your error handling is very sophisticated and therefore might throw an error itself, it is useful to add a flag indicating if you are already in "errorHandling-Mode". Like so:
var appIsHandlingError = false;window.onerror = function() { if (!appIsHandlingError) { appIsHandlingError = true; handleError(); }};function handleError() { // graceful error handling // if successful: appIsHandlingError = false;}
Otherwise you could find yourself in an infinite loop.