Skip to content

Commit f236a13

Browse files
authored
Spelling, wording, typos
1 parent 2a3182a commit f236a13

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

1-js/08-error-handling/1-try-catch/article.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Let's see more examples.
8181
````warn header="`try..catch` only works for runtime errors"
8282
For `try..catch` to work, the code must be runnable. In other words, it should be valid JavaScript.
8383

84-
It won't work if the code is syntactically wrong, for instance it has unmatched figure brackets:
84+
It won't work if the code is syntactically wrong, for instance it has unmatched curly braces:
8585
8686
```js run
8787
try {
@@ -98,7 +98,7 @@ So, `try..catch` can only handle errors that occur in the valid code. Such error
9898
9999
100100
````warn header="`try..catch` works synchronously"
101-
If an exception happens in a "scheduled" code, like in `setTimeout`, then `try..catch` won't catch it:
101+
If an exception happens in "scheduled" code, like in `setTimeout`, then `try..catch` won't catch it:
102102

103103
```js run
104104
try {
@@ -110,7 +110,7 @@ try {
110110
}
111111
```
112112

113-
That's because `try..catch` actually wraps the `setTimeout` call that schedules the function. But the function itself is executed later, when the engine has already have left the `try..catch` construct.
113+
That's because `try..catch` actually wraps the `setTimeout` call that schedules the function. But the function itself is executed later, when the engine has already left the `try..catch` construct.
114114
115115
To catch an exception inside a scheduled function, `try..catch` must be inside that function:
116116
```js run
@@ -172,9 +172,9 @@ try {
172172

173173
Let's explore a real-life use case of `try..catch`.
174174
175-
As we already know, JavaScript supports method [JSON.parse(str)](mdn:js/JSON/parse) to read JSON-encoded values.
175+
As we already know, JavaScript supports the [JSON.parse(str)](mdn:js/JSON/parse) method to read JSON-encoded values.
176176
177-
Usually it's used to decode the data received over the network, from the server or another source.
177+
Usually it's used to decode data received over the network, from the server or another source.
178178

179179
We receive it and call `JSON.parse`, like this:
180180

@@ -190,13 +190,13 @@ alert( user.name ); // John
190190
alert( user.age ); // 30
191191
```
192192

193-
More detailed information about JSON you can find in the chapter <info:json>.
193+
You can find more detailed information about JSON in the <info:json> chapter.
194194

195195
**If `json` is malformed, `JSON.parse` generates an error, so the script "dies".**
196196

197197
Should we be satisfied with that? Of course, not!
198198

199-
This way if something's wrong with the data, the visitor will never know that (unless he opens developer console). And people really really don't like when something "just dies" without any error message.
199+
This way, if something's wrong with the data, the visitor will never know that (unless he opens developer console). And people really don't like when something "just dies" without any error message.
200200

201201
Let's use `try..catch` to handle the error:
202202
@@ -220,11 +220,11 @@ try {
220220
}
221221
```
222222
223-
Here we use `catch` block only to show the message, but we can do much more: a new network request, suggest an alternative to the visitor, send the information about the error to a logging facility... All much better than just dying.
223+
Here we use the `catch` block only to show the message, but we can do much more: send a new network request, suggest an alternative to the visitor, send information about the error to a logging facility, ... . All much better than just dying.
224224
225225
## Throwing our own errors
226226
227-
What if `json` is syntactically correct... But doesn't have a required `"name"` property?
227+
What if `json` is syntactically correct, but doesn't have a required `name` property?
228228
229229
Like this:
230230
@@ -243,7 +243,7 @@ try {
243243
}
244244
```
245245
246-
Here `JSON.parse` runs normally, but the absence of `"name"` is actually an error for us.
246+
Here `JSON.parse` runs normally, but the absence of `name` is actually an error for us.
247247
248248
To unify error handling, we'll use the `throw` operator.
249249
@@ -297,7 +297,7 @@ try {
297297
298298
As we can see, that's a `SyntaxError`.
299299
300-
...And in our case, the absense of `name` could be treated as a syntax error also, assuming that users must have a `"name"`.
300+
And in our case, the absense of `name` could be treated as a syntax error also, assuming that users must have a `name`.
301301
302302
So let's throw it:
303303
@@ -321,7 +321,7 @@ try {
321321
}
322322
```
323323
324-
In the line `(*)` the `throw` operator generates `SyntaxError` with the given `message`, the same way as JavaScript would generate itself. The execution of `try` immediately stops and the control flow jumps into `catch`.
324+
In the line `(*)`, the `throw` operator generates a `SyntaxError` with the given `message`, the same way as JavaScript would generate it itself. The execution of `try` immediately stops and the control flow jumps into `catch`.
325325
326326
Now `catch` became a single place for all error handling: both for `JSON.parse` and other cases.
327327
@@ -340,7 +340,7 @@ try {
340340
// ...
341341
} catch(err) {
342342
alert("JSON Error: " + err); // JSON Error: ReferenceError: user is not defined
343-
// (not JSON Error actually)
343+
// (no JSON Error actually)
344344
}
345345
```
346346
@@ -480,7 +480,7 @@ The code has two ways of execution:
480480
481481
The `finally` clause is often used when we start doing something before `try..catch` and want to finalize it in any case of outcome.
482482
483-
For instance, we want to measure time that a Fibonacci numbers function `fib(n)` takes. Naturally, we can start measuring before it runs and finish afterwards. But what if there's an error during the function call? In particular, the implementation of `fib(n)` in the code below returns an error for negative or non-integer numbers.
483+
For instance, we want to measure the time that a Fibonacci numbers function `fib(n)` takes. Naturally, we can start measuring before it runs and finish afterwards. But what if there's an error during the function call? In particular, the implementation of `fib(n)` in the code below returns an error for negative or non-integer numbers.
484484
485485
The `finally` clause is a great place to finish the measurements no matter what.
486486
@@ -527,7 +527,7 @@ Otherwise, if `let` were made inside the `{...}` block, it would only be visible
527527
```
528528
529529
````smart header="`finally` and `return`"
530-
Finally clause works for *any* exit from `try..catch`. That includes an explicit `return`.
530+
The `finally` clause works for *any* exit from `try..catch`. That includes an explicit `return`.
531531
532532
In the example below, there's a `return` in `try`. In this case, `finally` is executed just before the control returns to the outer code.
533533

0 commit comments

Comments
 (0)