You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/10-error-handling/2-custom-errors/article.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -244,10 +244,10 @@ Often the answer is "No": we'd like to be "one level above all that". We just wa
244
244
The technique that we describe here is called "wrapping exceptions".
245
245
246
246
1. We'll make a new class `ReadError` to represent a generic "data reading" error.
247
-
2. The function `readUser` will catch data reading errors that occur inside it, such as `ValidationError` and `SyntaxError`, and generate `ReadError` instead.
247
+
2. The function `readUser` will catch data reading errors that occur inside it, such as `ValidationError` and `SyntaxError`, and generate a `ReadError` instead.
248
248
3. The `ReadError` object will keep the reference to the original error in its `cause` property.
249
249
250
-
Then the code that calls `readUser` will only have to check for `ReadError`, not for every kind of data reading errors.
250
+
Then the code that calls `readUser` will only have to check for `ReadError`, not for every kind of data reading errors. And if it needs more details of an error, it can check its `cause` property.
251
251
252
252
Here's the code that defines `ReadError` and demonstrates its use in `readUser` and `try..catch`:
0 commit comments