跳到主要内容

try/catch/finally

try {
1 = 1;
} catch (error) {
console.log(error.name);
}

废了,废了。浏览器截胡了。显示错误,却捕捉不到。

throw

try {
throw new Error('虽然没有错 ');
} catch (error) {
console.log(error.name);
console.log(error.message);
} finally {
console.log('1 = 1');
}

在异常处理结构中,大括号不能省略