Skip to content

Instantly share code, notes, and snippets.

@jhurliman
Created September 14, 2015 01:26
Show Gist options
  • Save jhurliman/9058db00d06ff7fe0525 to your computer and use it in GitHub Desktop.
Save jhurliman/9058db00d06ff7fe0525 to your computer and use it in GitHub Desktop.
Difference between "return new Error()" and "throw new Error" in bluebird
var P = require('bluebird');
P.resolve().then(function () {
// Change this to throw new Error to get the expected behavior
if (true) return new Error('Returned error');
return { key: { subKey: 'test' } };
}).then(function (obj) {
// This will crash if return new Error is used since the Error is not caught by bluebird
console.log('obj.key.subKey = %s', obj.key.subKey);
}).catch(function (err) {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment