I looked at bluebird promises and as promised. different than the promise. Solved. Then an error occurs. First, some code using prom.try, where it generates a synchronous error
Promise.try(function() { throw new Error('error'); }).catch(function(e) { console.log(e); });
second code that causes a synchronous error when resolving
Promise.resolve().then(function() { throw new Error('error'); }).catch(function(e) { console.log(e); });
As far as I know, they both behave the same. Did he promise, in fact, a cleaner way to deliver on this promise?
The docs say prom.try:
will catch all errors in its Promise.catch handlers instead of handling synchronous and asynchronous exception flows.
In the case of the example given in the docs:
function getUserById(id) { return Promise.try(function() { if (typeof id !== "number") { throw new Error("id must be a number"); } return db.getUserById(id); }); }
if a synchronous error is selected, the asynchronous code will never be reached. Will there be any difference if you put the code above in the promise .resolve (), then (..)?
Any clarification / examples of prom.try would be much appreciated.
promise bluebird
user3710396
source share