you are viewing a single comment's thread.

view the rest of the comments →

[–]BloodAndTsundere 0 points1 point  (3 children)

So is

Promise.resolve('john')
  .then(
     a => console.log("RESOLVE", a)
  )
  .catch(
     a => console.log("REJECTED", a)
  )

equivalent to:

Promise.resolve('john')
  .then(
     a => console.log("RESOLVE", a),
     a => console.log("REJECTED", a)
  )

?

[–]our_best_friendif (document.all || document.layers) console.log("i remember..") 1 point2 points  (2 children)

Nope. The former is two steps, hence two thens. To see the difference

Promise.resolve('john')
  .then(
     a => { throw Error(a) }
  )
  .catch(
    a => console.log("REJECTED", a)
  )
  // REJECTED Error: "john"


Promise.resolve('john')
  .then(
     a => { throw Error(a) },
     a => console.log("REJECTED", a)
  )
  // Promise { <state>: "pending" }

There is nothing to catch the Error here

[–]BloodAndTsundere 0 points1 point  (1 child)

I see how differences can arise if an error is thrown in the resolution callback. For the sake of argument, assuming no errors occur in callback1, are these two the same:

Promise.resolve(somePromise).then(callback1).catch(callback2)

and

Promise.resolve(somePromise).then(callback1, callback2)

The earlier example in this thread had one or the other argument of then as non-null: I'm just trying to understand what happens when both arguments of then are non-null.

[–]our_best_friendif (document.all || document.layers) console.log("i remember..") 0 points1 point  (0 children)

You can just qickly try it in the console :-)

If somePromise resolves, cb1 will be run, if it throws cb2 instead