Skip to content

Custom errors, extending Error #85

New issue

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

Merged
merged 2 commits into from
Sep 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ importance: 5

---

# Finally or just the code?
# Finally ou juste le code?

Compare the two code fragments.
Comparez les deux fragments de code.

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.
Loading