Using Q.promises: how to catch an async throw?

為{幸葍}努か 提交于 2019-11-27 16:18:24

The exception in the setTimeout is not related anyhow to the promises, you have to catch that yourself using a try-catch-block.

Or you use Q.delay:

function func(){
    return Q.delay(100).then(function(){
        throw new Error("async error");
    });
}

func()
.then(console.log.bind(console, "success"))
.fail(console.log.bind(console));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!