db.collection.findOne
is an async operation (MongoDB, but that doesn\'t really matter here), which is why I\'m wrapping it in a promise here.
var l
It is not swallowing that error, but if a then
or catch
handler results in an error, then the current promise will be rejected with that error.
In your case, ReferenceError
is thrown, but it rejects the promise. You can see the actual error being propagated, by attaching a catch
handler, like this
new Promise(function (resolve, reject) {
resolve(true);
})
.then(function (result) {
console.log(result, bar);
})
.catch(function (er) {
console.error('Inside Catch', er);
});
Now you will see
Inside Catch [ReferenceError: bar is not defined]
Further Reading: