使用 Q Promise 处理错误

Posted

技术标签:

【中文标题】使用 Q Promise 处理错误【英文标题】:Error handling with Q promise 【发布时间】:2014-06-21 17:51:06 【问题描述】:

所以,我有以下代码

Q.fcall(foo(input))
.then(
  () ->
    # do stuff
)
.fail(
  # this never gets called
)

foo = (input) ->
  throw new Error('catch me!')

我收到以下错误:Uncaught Error: catch me!。根据docs .fail 调用应该捕获foo 引发的任何错误 - 我做错了吗?

【问题讨论】:

foo的代码是什么? 为了示例,foo 只是一个在调用时抛出错误的方法。 【参考方案1】:

应该是Q.fcall(foo, input)

【讨论】:

非常感谢,真不敢相信我在文档中错过了这一点! :-)

以上是关于使用 Q Promise 处理错误的主要内容,如果未能解决你的问题,请参考以下文章

使用 axios 时可能出现未处理的 Promise 拒绝、网络错误

HTTP Promise - 处理错误

如何在 reducer 中处理 Redux 的 redux-promise 中间件 AJAX 错误?

处理 Promise 执行器函数 ESLint 错误

如何正确处理 Promise 链中的错误?

在 Javascript 中将多个 Promise 推入数组时处理单个错误