This applies to functions that are async as well in babel:
async function get(url) {
throw new Error('hi there');
}
// wont throw the error
get('http://google.com');
// catch the error
get('http://google.com').catch(function(err) {
throw err;
});On the other hand, there's really no reason not to use Bluebird. It's easy to ensure that a promise you receive is a Bluebird promise:
import Bluebird from 'bluebird';
const bluebirdPromise = Bluebird.resolve(promise);
If `promise` is a Bluebird promise that will be a no-op, and if it's a foreign promise or thennable you'll get a new Bluebird promise that will resolve/reject when the foreign one does. (This is standard behavior; see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...)Since Bluebird promises are thennables, the reverse will be true if they're consumed by a different promise library.
Given Bluebird's speed, superior debuggability, and features, there's really no reason not to use it a this point.
I was bitten by bluebird quietly eating exceptions on at least one codebase. I fixed it by re-throwing them via: https://github.com/petkaantonov/bluebird/blob/master/API.md#...
edit: bluebird also exposes a process-level event, now, too!
http://jsfiddle.net/sb1zqjdm/ (using native promises)
And it seems that the "Pause on exceptions" debugger feature works on unhandled promise errors. Doesn't seem too bad to me.
But then again, in it's current "minimal" state of design, the Harmony Promises are inferior to any of the dedicated Promise A Plus implementations out there (e.g. Bluebird) and at least under Node there is little to no reason to use the built-in Promise object at this point in time.
I know some Promise libraries have an option to report unhandled errors which makes life a lot easier but there really should be something natively too.
This mistake is going to be most frustrating for those who don't realize that "unhandledRejection" is a case they even need to consider. People learning JS and having nothing happen when they run (erroneous) code are going to be pulling their hair out.
something().then(function(){
setTimeout(function(){
whoops_not_a_function();
}, 1000);
}).catch(function(){
// nope, nothing to catch
}); something().then(() => {
return Promise.delay(1000).then(() => {
whoops_not_a_function();
});
}).catch(() => {
// whoops_not_a_function is not defined
});
...or write Promise_delay yourself on top of native promises (but really just use Bluebird).