The following eight error types are defined in the ECMS and different error objects are thrown when an error occurs.
- Error
- InternalError
- EvalError
- RangeError
- ReferenceError
- SyntaxError
- TypeError
- URIError
A, the Error
Error is the base type from which all other Error types inherit, so all Error types share the same properties (all methods on Error objects are methods defined by the default type). Browsers rarely throw errors of the Error type, which is mainly used by developers to throw custom errors. For example, interceptors/navigators are often used.
Second, the InternalError
An error of type InternalError is thrown by the browser when an exception is thrown by the underlying JavaScript engine. For example, too much recursion leads to stack overflow. This type of error is not typically handled in code, and if it does occur, there is a good chance that something is wrong or dangerous in the code.
Third, EvalError
An EvalError type error is thrown when an exception occurs using the eval() function. Ecma-262 states that ‘if the eval attribute is not called directly (that is, without using its name as an Identifier, which is MemberExpression in CallExpression). Basically, an error is reported whenever eval() is not called as a function. Errors thrown by different browsers vary, but they are rarely used, so they are not common
Four, RangeError
RangeError is raised when a value is out of bounds. For example, if an array is defined with an unsupported length, such as -20. Or if a stop condition is not set for recursion. This type doesn’t happen much in JavaScript
Five, the ReferenceError
ReferenceError occurs when an object cannot be found (the cause of the famous “object Expected “browser error). This error is often caused by accessing variables that do not exist. Ex. :
Six, SyntaxError
This often happens when the string passed to eval() contains a JavaScript syntax error, which is rarely used outside eval(). This is because syntax errors in JavaScript code cause the code to fail to execute.
TypeError,
Typeerrors are common in JavaScript. They occur when a variable is not of the expected type, or when a nonexistent method is accessed, especially if the variable is of the wrong type when a type-specific operation is used. Errors occur frequently without validation before passing parameters to a function
Eight, URIError
URIError only occurs when encodeURL() or decodeURL() is used and a malformed URL is passed in, but it is very rare because the above two functions are very robust.