//try里面如果发生错误就跳出,但不报错,继续执行
try {
console.log('a'); //打印a
console.log(b); //有错误,跳出
console.log('c');
} catch(error) {
//一般打印错误信息
//用来捕捉错误,如果try没错误不执行catch,有错误才执行
console.log(error.name + " : " + error.message);
//打印:ReferenceError : b is not defined
}
console.log('d'); //打印d
目前我们可能得到的系统异常主要包含以下6种:
- EvalError: eval()的使用和定义不一样
- RangeError: 数组越界
- ReferenceError: 非法或不能识别引用数值
- SyntaxError: 发生语法解析错误
- TypeError: 操作数类型错误
- URIError: URL处理函数使用不当