Javascript error types are: 1. Error; 2. InternalError; 3. EvalError; 4. RangeError; 5. ReferenceError; 6. SyntaxError; 7. TypeError; 8. URIError.
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
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. InternalError
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
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()
The errors thrown by different browsers will be different, but it is rarely used in this way, so it is not common.
Four , RangeError
This type does not occur much in
Example:
Often when the string passed to eval() contains
JavaScript7. TypeError
##TypeError
. 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
URIError 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.
]
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!