JavaScript Error Types
JavaScript error types are the constructors behind every error the engine throws, such as TypeError and RangeError. ECMAScript defines a fixed set of native error types, and each one gets its own entry here. An entry says when the engine throws the type and shows how to catch it and tell it apart from the others.
Each entry lists the messages its type carries most often, as Chrome and Node.js print them, with the usual cause and a fix for each, plus a second table of the Firefox and Safari wording where it differs. To find the right entry, read the first word of the line in the console, such as TypeError in TypeError: x is not a function.
Topics covered include:
- Base and legacy errors: The general type that every error extends, plus the old type for
eval()(Error,EvalError) - Runtime errors: The types the engine throws while code runs (
TypeError,ReferenceError,RangeError) - Parse errors: The types for source code, JSON, and URIs that can’t be parsed (
SyntaxError,URIError) - Aggregate errors: The types that bundle several errors into one (
AggregateError,SuppressedError)
The try, catch, and throw statements live in JavaScript Keywords. Concepts such as exceptions and stack traces belong in the JavaScript Glossary. Other global objects, including Promise and JSON, live in Standard Built-in Objects. This area picks up the error constructors and the messages they carry.