← 返回完整题库
JavaScript简单

一个promise链式调用,中途抛出了错误,被catch捕获了,那么catch后面的then还会执行吗?

参考答案

会执行。

.catch() 返回的是新的 fulfilled Promise(只要它内部没有再次抛错),因此后续 .then 继续走成功分支,且收到的值是 catch 的返回值。

Promise.reject(new Error('x'))
  .catch(e => 'recovered')
  .then(v => console.log(v));   // 'recovered'

若 catch 里又 throw(或返回 rejected Promise),则后续 then 被跳过,进入下一个 catch。

本题来自 计算机知识面试题库,共 921 道题。