// NODE JS
process.on('uncaughtException', function (error) {
// Handle the error
});
// Browser
window.onunhandledrejection = event => {
console.warn(`UNHANDLED PROMISE REJECTION: ${event.reason}`);
};
window.onerror = function(message, source, lineNumber, colno, error) {
console.warn(`UNHANDLED ERROR: ${error.stack}`);
};
// OR
window.addEventListener('error', function(event) { ... })
process.on('uncaughtException', function (err) { console.log('Caught exception: ' + err);});