This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The difference becomes obvious when we look at the code inside a function.
La différence devient évidente quand on regarde le code dans une fonction.
The behavior is different if there's a "jump out" of `try..catch`.
Le comportement est différent s'il y a un "saut" en dehors de `try..catch`.
For instance, when there's a `return` inside `try..catch`. The `finally` clause works in case of *any* exit from `try..catch`, even via the `return` statement: right after `try..catch` is done, but before the calling code gets the control.
Par exemple, quand il y a un `return` dans `try..catch`. La clause `finally` fonctionne en cas de *toute* sortie de` try..catch`, même via l'instruction `return`: juste après la fin de `try..catch`, mais avant que le code appelant obtienne le contrôle.
```js run
function f() {
Expand All
@@ -21,7 +21,7 @@ function f() {
f(); // cleanup!
```
...Or when there's a `throw`, like here:
...Ou quand il y a un `throw`, comme ici:
```js run
function f() {
Expand All
@@ -44,4 +44,4 @@ function f() {
f(); // cleanup!
```
It's `finally` that guarantees the cleanup here. If we just put the code at the end of `f`, it wouldn't run in these situations.
C'est `finally` qui garantit le nettoyage ici. Si nous mettons simplement le code à la fin de `f`, il ne fonctionnerait pas dans ces situations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. The first one uses `finally` to execute the code after `try..catch`:
1. Le premier utilise `finally` pour exécuter le code après `try..catch`:
```js
try {
Expand All
@@ -19,7 +19,7 @@ Compare the two code fragments.
*/!*
}
```
2. The second fragment puts the cleaning right after `try..catch`:
2. Le deuxième fragment met le "cleanup" juste après `try..catch`:
```js
try {
Expand All
@@ -33,6 +33,6 @@ Compare the two code fragments.
*/!*
```
We definitely need the cleanup after the work, doesn't matter if there was an error or not.
Nous avons absolument besoin du nettoyage après le travail, peu importe qu'il y ait une erreur ou non.
Is there an advantage here in using `finally` or both code fragments are equal? If there is such an advantage, then give an example when it matters.
Y at-il un avantage ici à utiliser `finally` ou les deux fragments de code sont égaux? Si un tel avantage existe, donnez un exemple lorsque cela compte.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Custom errors, extending Error #85
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Custom errors, extending Error #85
Filter by extension
Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Uh oh!
There was an error while loading. Please reload this page.