捕获 Promise 的错误
约 129 字小于 1 分钟
2026-03-31
下面代码执行结果是什么?
JS code example
console
Click the run button to execute the code ...
Promise.reject 会进入失败处理,.then 第二个参数可以捕获上一个 Promise 的错误,.catch 可以捕获任何未处理的 reject 与抛错。
上面的代码中,Promise.reject 会进入失败处理,进入 .then 第二个参数,输出 "error!!" "error!"。
拓展阅读:捕获 Promise 的错误