Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I prevent that Chrome (v45) pauses on promise rejections?

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.

like image 766
Mikael Sundberg Avatar asked Sep 24 '15 07:09

Mikael Sundberg


1 Answers

Chrome only does this if you have "pause on uncaught exception" turned on in the "Sources" tab.

enter image description here

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
like image 107
Benjamin Gruenbaum Avatar answered Sep 21 '22 11:09

Benjamin Gruenbaum