- Architecting Angular Applications with Redux,RxJS,and NgRx
- Christoffer Noring
- 118字
- 2021-08-27 19:56:23
Handling rejected promises
For a rejected promise, we have two ways of handling it: we can either use the second callback in the .then() method, or we can use the .catch() method. Here are the two versions available to us:
// alternative 1
getMoreData().then(
data => {
console.log('data',data);
},
err => {
console.log('error',err);
}
)
// alternative 2
getMoreData().then(data => {
console.log('data', data);
})
.catch((err) => {
console.log('error', err);
});
In the first case, we have a second callback added to the then() method, and in the second version, we chain a catch() method to the existing then() method. They are equivalent so you can use either one, but only one.
推薦閱讀
- RCNP實驗指南:構建高級的路由互聯網絡(BARI)
- 自動駕駛網絡:自智時代的網絡架構
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 網絡的琴弦:玩轉IP看監控
- PLC、現場總線及工業網絡實用技術速成
- 物聯網時代
- 大話社交網絡
- TD-LTE無線網絡規劃與設計
- 工業互聯網創新實踐
- 語音信號處理及Blackfin DSP實現
- 園區網絡架構與技術
- 5G非正交多址接入技術:理論、算法與實現
- 物聯網基礎及應用
- 深入理解計算機網絡