使用 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 拒绝、网络错误