
上QQ阅读APP看书,第一时间看更新
How it works...
Previously we saw how to use resolve to return a value in the case of a successful fulfillment of a promise. In this case we called reject before resolve. This means that the Promise finished with an error before it could resolve.
When the Promise completes in an error state, the then callbacks are not executed. Instead we have to use catch in order to receive the error that the Promise rejects. You'll also notice that the catch callback is only executed after the main function has returned. Like successful fulfillment, listeners to unsuccessful ones execute asynchronously.