javascript - Why does Promise.reject() require a return? -


in following code promise.reject doesn't work unless use return promise.reject(...). why this?

promise.resolve('promise 1 done') .then(function(result) {   console.log(result);   return 'promise 2 done' }).then(function(result) {   let j;   try {     j = json.parse("invalid throw");     console.log(j);   } catch(err) {     promise.reject('could not parse json');   }    console.log(result); }).catch(function(err) {   console.log(err); }); 

promise.reject creates value, not throw exception breaks function throw does. if don't return value, ignored , control flow continues.

given inside promise callback, (and possibly should) instead use

throw new error('could not parse json'); 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -