If I have the developer tools visible in Chrome and a Promise is rejected, then Chrome pauses the javascript execution with the message "Paused on promise rejection". Can I in some way prevent Chrome from pause in this case (and still have devtools open)?
Rejected promises is a part of the "normal" flow in my application and it's inconvenient to press the resume button in Chrome every time it happens.
You can test this behaviour in Chrome by entering the following in the js-console:
new Promise(function(accept, reject) { reject(); }) // (tested in v 45.0.2454.99)
Thanks.
Chrome only does this if you have "pause on uncaught exception" turned on in the "Sources" tab.
If you untick it it will not pause on errors.
A promise rejection is conceptually an error. It is the correct way to mentally model it, otherwise the following are silent errors:
Promise.resolve().then(function(){
JSON.prase("{}"); // unhandled rejection, TypeError, typo
foooooo = 15; // unhandled ReferenceError, undefined
});
And so on.
If you want to explicitly suppress a rejection, which is akin to a synchronous "catch all" you'd do the same thing you do in synchronous code:
try {
doSomething();
} catch(e){
// explicitly ignore all errors.
}
With promises:
doSomething().catch(function(){}); // explicitly don't report rejection
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With