Google Chrome: Unhandled Promise.reject() global handling via the window.onunhandledrejection event

Viewed 282

Windows 10 x64
Google Chrome 62.0.3202.94 x64

My code snippet:

let rejected;

// unhandled rejection handling...
window.onunhandledrejection = function(e) {
 // Handle this case... For example I can send info
 // about this error to developer's email.
 console.log('Unhandled rejection info:');
 console.log(e.type);
 console.log(e.reason.message);
 console.log(rejected === e.promise);
};

// Some unhandled rejection...
rejected = Promise.reject(new Error('Foo'));

This code works in the stackoverflow code snippet, but it doesn't work if I try to use it in my js-file in GoogleChrome:

enter image description here

Why does it happen and how can I fix it?

0 Answers
Related