Did some tests on my own and found that an error handler inside .then() or .catch() does NOT catch an error in 'value' of Promise.resolve(value), but DOES catch it in a Promise constructors resolve(value).
I tried both Promise.resolve and a promise constructor with resolve 'value' that throws an error (tried using an undefined variables and also an outside function that throws an error). Both had .then and .catch following.
I THINK I get the idea that in Promise.resolve, 'value' is evaluated before it is 'sent' to then - so JavaScript throws an exception and shuts it all down before it gets a chance to be caught by .then or .catch. But why does the same not happen with the resolve(value) in the promise constructor.
Just to clarify:
In the following case, JavaScript reports an unhandled exception and everything stops:
Promise.resolve(someError)
.catch(() => {
console.error('This never gets printed');
})
but...
In the case below, .catch DOES catch the error and print its message:
new Promise ((resolve, reject) => {
resolve(someError)
})
.catch(() => {
console.error('This actually gets printed');
})