function throwError(){
throw new Error('ERROR');
}
try{
setTimeout(throwError, 0);
} catch(e){
alert(e);//这里的异常无法捕获
}
这样可以
function throwError(){
try{
throw new Error('ERROR');
}
} catch(e){
alert(e);//这里的异常无法捕获
}
setTimeout(throwError, 0);
为什么第一个例子的异常不能捕获?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
因为是异步操作。