commit
58d72b660e
1 changed files with 2 additions and 2 deletions
|
@ -85,7 +85,7 @@ try {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The JavaScript engine first reads the code, and then runs it. The errors that occur on the reading phrase are called "parse-time" errors and are unrecoverable (from inside that code). That's because the engine can't understand the code.
|
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.
|
||||||
|
|
||||||
So, `try..catch` can only handle errors that occur in the valid code. Such errors are called "runtime errors" or, sometimes, "exceptions".
|
So, `try..catch` can only handle errors that occur in the valid code. Such errors are called "runtime errors" or, sometimes, "exceptions".
|
||||||
````
|
````
|
||||||
|
@ -522,7 +522,7 @@ alert(result || "error occurred");
|
||||||
alert( `execution took ${diff}ms` );
|
alert( `execution took ${diff}ms` );
|
||||||
```
|
```
|
||||||
|
|
||||||
You can check by running the code with entering `35` into `prompt` -- it executes normally, `finally` after `try`. And then enter `-1` -- there will be an immediate error, an the execution will take `0ms`. Both measurements are done correctly.
|
You can check by running the code with entering `35` into `prompt` -- it executes normally, `finally` after `try`. And then enter `-1` -- there will be an immediate error, and the execution will take `0ms`. Both measurements are done correctly.
|
||||||
|
|
||||||
In other words, the function may finish with `return` or `throw`, that doesn't matter. The `finally` clause executes in both cases.
|
In other words, the function may finish with `return` or `throw`, that doesn't matter. The `finally` clause executes in both cases.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue