0

oh i really want to know about promise in js.

what if i do this.

var p = somePromise;
p.then(doSomething1);

p.then(doSomething2);

p.catch(doSomething3);

then the result is 1->2 ` but if i do this:

p.then(doSomething1).then(throw some error);

p.then(doSomething2);

p.catch(doSomething3);

1 ->3 and report a unhandled rejection. why???

Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
moon.pike
  • 1
  • 3
  • forgive my text... I don't do good format. – moon.pike Apr 22 '18 at 06:15
  • 1
    I can't really tell what you're asking, but it looks like maybe you need to understand the difference between [Understanding javascript promises; branches and chaining](https://stackoverflow.com/questions/29853578/understanding-javascript-promises-stacks-and-chaining/29854205#29854205) and also [Promise chaining vs. branching](https://stackoverflow.com/questions/32216619/is-there-a-difference-between-promise-then-then-vs-promise-then-promise-then/32216660#32216660) which you can read about in both those answers. – jfriend00 Apr 22 '18 at 06:55
  • 1
    Another related reference: [Chaining Javascript Promises](https://stackoverflow.com/questions/38451166/chaining-javascript-promises/38451211#38451211). – jfriend00 Apr 22 '18 at 07:00
  • Promises are resolved or rejected only once. In the second example you are using the `p` promise by doing `p.then(doSomething1).then(throw some error);` in which the thrown error is not handled. – Redu Apr 22 '18 at 08:18

0 Answers0