【发布时间】:2020-12-03 13:28:48
【问题描述】:
我是 JavaScript 的初学者,当第三方异步函数发生错误时,我很难在主线程中抛出消息错误:
function mainThread(){
try{
myFunction(param1, error => {
throw error // Error is not catched
})
}
catch (error)
{
"i would like to catch the error here in the main thread"
}
}
function myFunction(param1, callback) {
asyncThirdpartyfunction(param1, (err) => {
if (err)
callback(err)
})
}
错误在我的控制台中被抛出,没有被 catch 处理。 怎么了?我该怎么做才能在我的主线程中获取错误值? 我尝试了很多回调和承诺的事情,但他们没有做我想要的。
【问题讨论】:
标签: javascript callback throw