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/1-try-catch/article.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ No matter how great we are at programming, sometimes our scripts have errors. Th
4
4
5
5
Usually, a script "dies" (immediately stops) in case of an error, printing it to console.
6
6
7
-
But there's a syntax construct `try..catch` that allows to "catch" errors and, instead of dying, do something more reasonable.
7
+
But there's a syntax construct `try..catch` that allows us to "catch" errors so the script can, instead of dying, do something more reasonable.
8
8
9
9
## The "try..catch" syntax
10
10
@@ -26,13 +26,13 @@ It works like this:
26
26
27
27
1. First, the code in `try {...}` is executed.
28
28
2. If there were no errors, then `catch(err)` is ignored: the execution reaches the end of `try` and goes on, skipping `catch`.
29
-
3. If an error occurs, then `try` execution is stopped, and the control flows to the beginning of `catch(err)`. The `err` variable (can use any name for it) will contain an error object with details about what happened.
29
+
3. If an error occurs, then the `try` execution is stopped, and control flows to the beginning of `catch(err)`. The `err` variable (can use any name for it) will contain an error object with details about what happened.
30
30
31
31

32
32
33
-
So, an error inside the `try {…}` block does not kill the script: we have a chance to handle it in `catch`.
33
+
So, an error inside the `try {…}` block does not kill the script -- we have a chance to handle it in `catch`.
34
34
35
-
Let's see examples.
35
+
Let's look at some examples.
36
36
37
37
- An errorless example: shows `alert``(1)` and `(2)`:
38
38
@@ -87,7 +87,7 @@ try {
87
87
88
88
The JavaScript engine first reads the code, and then runs it. The errors that occur on the reading phase are called "parse-time" errors and are unrecoverable (from inside that code). That's because the engine can't understand the code.
89
89
90
-
So, `try..catch` can only handle errors that occur in the valid code. Such errors are called "runtime errors" or, sometimes, "exceptions".
90
+
So, `try..catch` can only handle errors that occur in valid code. Such errors are called "runtime errors" or, sometimes, "exceptions".
0 commit comments