Home  >  Article  >  Web Front-end  >  What are the error types in javascript

What are the error types in javascript

青灯夜游
青灯夜游Original
2021-10-14 17:04:182229browse

Javascript error types are: 1. Error; 2. InternalError; 3. EvalError; 4. RangeError; 5. ReferenceError; 6. SyntaxError; 7. TypeError; 8. URIError.

What are the error types in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

The following eight error types are defined in ECMS and different error objects are thrown when an error occurs.

  • Error

  • InternalError

  • EvalError

  • RangeError

  • ##ReferenceError

  • SyntaxError

  • TypeError

  • ##URIError

  • 1. Error

Error

is the base type. Other error types inherit this type. Therefore, all error types are Share the same properties (all methods on the error object are methods defined by this default type). Browsers rarely throw Errortype errors, which are mainly used by developers to throw custom errors. For example, it is often used in interceptors/navigation guards.

##2. InternalErrorWhat are the error types in javascript

InternalError

type errors will be caused when the underlying

JavaScript engine throws an exception. Browser throws. For example, too much recursion causes stack overflow. This type of error is not usually handled in the code. If this kind of error does occur, it is likely that the code is wrong or dangerous. 3. EvalError

EvalError

Type error will be thrown when an exception occurs using the eval() function. ECMA-262 stipulates, 'If the

eval attribute is not called directly (that is, its name is not used as an Identifier (identifier), that is, in CallExpression MemberExpression). Basically, as long as eval()

is not regarded as a function call, an error will be reported.

The errors thrown by different browsers will be different, but it is rarely used in this way, so it is not common.

Four , RangeErrorWhat are the error types in javascript

RangeError

will be thrown when the value goes out of bounds. For example, if an unsupported length is set when defining an array, such as -20. Or it may be triggered when no stop condition is set for the recursion.

This type does not occur much in

JavaScript

What are the error types in javascript

##5 , ReferenceError

What are the error types in javascript

ReferenceError

will occur when the object cannot be found. (This is the cause of the famous "object expected" browser error). This error is often caused by accessing a variable that does not exist.

Example:

6. SyntaxError

What are the error types in javascriptOften when the string passed to eval() contains

JavaScript

A syntax error occurs. This type of error is rarely used outside eval()

. This is because syntax errors in JavaScript code can cause the code to fail to execute.

7. TypeError##TypeError

is very common in

JavaScript

. It mainly occurs when the variable is not of the expected type or cannot be accessed. Existing methods, etc., especially when using type-specific operations and the variable type is wrong. When there is no verification before passing parameters to the function, errors frequently occur

8. URIError

URIErrorWhat are the error types in javascript will only occur when using encodeURL() or decodeURL() but passing in a malformed URL, but it is very rare because the above two functions are very robust.

[Recommended learning:

javascript advanced tutorial

]

The above is the detailed content of What are the error types in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn