Skip to content

错误处理机制 #98

Open
Open
@funnycoderstar

Description

@funnycoderstar

Error类型

  • EvalError(eval错误)
  • RangeError(范围错误)
  • ReferenceError(引用错误)
  • SyntaxError(语法错误)
  • TypeError(类型错误)
  • URIError(URI错误)

常见的有 ReferenceError(引用错误), SyntaxError(语法错误), TypeError(类型错误)

ReferenceError(引用错误)

引用一个不存在的变量或者左值类型错误时,会触发。

console.log(a); // ReferenceError: Cannot access 'a' before initialization
let a = 1;

SyntaxError(语法错误)

当不符合语法规则时,会抛出SyntaxError(语法错误)

// 变量名错误
let 1a; // SyntaxError: Invalid or unexpected token

TypeError(类型错误)

在变量中保存着意外的类型,或者再访问不存在的方法时,都会导致 TypeError(类型错误)

const o = new 10; // TypeError: 10 is not a constructor

参考

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @funnycoderstar

        Issue actions

          错误处理机制 · Issue #98 · funnycoderstar/blog