JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)
What are the different error names from error object
There are 7 different types of error names returned from error object,
| Error Name | Description |
|---|---|
AggregateError | An error indicating that multiple errors occurred |
EvalError | An error has occurred in the eval() function |
RangeError | An error has occurred with a number "out of range" |
ReferenceError | An error due to an illegal reference |
SyntaxError | An error due to a syntax error |
TypeError | An error due to a type error |
URIError | An error due to encodeURI() |
Practical Code Example
javascript
// Core Error Names in JavaScript:
try {
// null.f(); // TypeError
// undeclaredVar; // ReferenceError
// eval('foo bar'); // SyntaxError
// decodeURI('%'); // URIError
// new Array(-1); // RangeError
} catch (err) {
console.log(err.name); // e.g., 'TypeError'
console.log(err.message); // Explanatory message
}