【ES6】Promise的then中的异常处理方法(第二个方法)和catch有什么区别

主要区别就是,如果在 then 的第一个函数里抛出了异常,后面的 catch 能捕获到,而第二个函数捕获不到

p.then(function () {
    throw new Error()
  }, function () {
    // won't capture this error
  })
  .catch(function () {
    // will capture the error
  })

 

posted @ 2021-02-22 16:52  vickylinj  阅读(1560)  评论(0编辑  收藏  举报