JS Promise Notes

 

  • use Promise.resolve and .reject to handle exceptions instead of try catch
  • when exception is thrown inside promise it goes to .catch() but when it’s inside a method in promise, it doesn’t invoke catch
  • to have .then not invoked, reject the promise
  • .then and .catch chaining doesn’t work like : .then1.catch1.then2.catch2. In case of error in then1 or then2, catch1 will be invoked and never catch2.
  • If there are multiple .then, wrap them all in a promise
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s