当前位置:网站首页>Es6--- two methods of capturing promise status as failed

Es6--- two methods of capturing promise status as failed

2022-07-06 15:27:00 Cirrod

1.try cath Method

    async fn() {
       try {
         await promise object 
       } catch (err) {
         console.log(err)// Capture failed promise
       }

    }

2. adopt promise The built-in .catch() Method

    async fn() {

      await promise object .catch(err => {

          console.log(err)// Capture failed promise
    
      })
    }

原网站

版权声明
本文为[Cirrod]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131318482335.html