1. 错误类型

类型名称 描述
EvalError 与 eval() 有关。
InternalError 递归太多
RangeError 数值变量或参数超出其有效范围。
ReferenceError 无效引用
SyntaxError eval()在解析代码的过程中发生的语法错误
TypeError 变量或参数不属于有效类型
URIError encodeURI()decodeURl()传递的参数无效。

2. 处理错误

  1. "use strict";
  2. let errorType = null,
  3. number = null;
  4. try {
  5. console.log(errorType.length);
  6. number = 100
  7. } catch (e) {
  8. console.log(e);
  9. } finally {
  10. console.log('代码不管执不执行try catch 都会执行这一行代码');
  11. }
  12. console.log(errorType);
  13. console.log(number);