![ECMAScript Cookbook](https://wfqqreader-1252317822.image.myqcloud.com/cover/58/36700058/b_36700058.jpg)
上QQ阅读APP看书,第一时间看更新
Simulating finally with the promise API
In a previous recipe, we saw how catch can be used to handle errors, whether a promise has rejected, or a callback has thrown an error. Sometimes, it is desirable to execute code whether or not an error state has been detected. In the context of try/catch blocks, the finally block can be used for this purpose. We have to do a little more work to get the same behavior when working with promises
In this recipe, we'll see how a final then call to execute some code in both successful and failing fulfillment states.