我无法弄清楚如何从调用的函数中捕获异常image.onload
。请注意以下示例:
function afterImgLoads() {
throw 'This is being thrown from img.onload!';
}
try {
var img = new Image();
img.onload = afterImgLoads;
img.src = 'path/to/valid/image.jpg';
} catch(e) {
throw 'This is being thrown after setting img.src';
}
在上面的示例中,我无法弄清楚如何在afterImgLoads()
抛出自己的错误时抛出第二个 throw 语句。