Update 102-utilizing-error-objects.md (#2136)

pull/1929/head^2
puru-khedre 2 years ago committed by GitHub
parent ebdbbcc616
commit 2a942748f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 35
      content/roadmaps/106-javascript/content/107-javascript-control-flow/100-exception-handling/102-utilizing-error-objects.md

@ -1 +1,34 @@
# Utilizing error objects
# Utilizing error objects
When a runtime error occurs, a new `Error` object is created and thrown. With this `Error` object, we can determine the type of the Error and handle it according to its type.
## Types of Errors:
Besides error constructors, Javascript also has other core Error constructors.
- [`AggregateError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError)
- [`EvalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/EvalError)
- [`InternalError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/InternalError)
- [`RangeError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError)
- [`ReferenceError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError)
- [`SyntaxError`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError)
## Example
```js
try {
willGiveErrorSometime();
} catch (error) {
if (error instanceof RangeError) {
rangeErrorHandler(error);
} else if (error instanceof ReferenceError) {
referenceErrorHandle(error);
} else {
errorHandler(error);
}
}
```
<ResourceGroupTitle>Free Content</ResourceGroupTitle>
<BadgeLink colorScheme='yellow' badgeText='Read' href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error'>Error Object - MDN</BadgeLink>
<BadgeLink colorScheme='yellow' badgeText='Read' href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling'>Control flow & Error handling - MDN</BadgeLink>

Loading…
Cancel
Save