【发布时间】:2012-11-08 00:58:00
【问题描述】:
我不知道如何从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 语句。
【问题讨论】:
标签: javascript image exception-handling try-catch