Skip to content

Commit 3ac6b27

Browse files
committed
Custom errors, extending Error
1 parent 2899955 commit 3ac6b27

File tree

6 files changed

+95
-95
lines changed

6 files changed

+95
-95
lines changed

1-js/10-error-handling/1-try-catch/1-finally-or-code-after/solution.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
The difference becomes obvious when we look at the code inside a function.
1+
La differenza diventa ovvia quando inseriamo il codice all'interno di una funzione.
22

3-
The behavior is different if there's a "jump out" of `try..catch`.
3+
Il comportamento è differente se c'è un salto dall'interno del `try..catch`.
44

5-
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.
5+
Per esempio, quando c'è un `return` all'interno del `try..catch`. La clausola `finally` funziona indipendentemente da come termina il `try..catch`, anche nel caso avvenga tramite un `return`: subito dopo la conclusione del `try..catch`, ma prima che il codice richiamato prenda il controllo.
66

77
```js run
88
function f() {
@@ -21,7 +21,7 @@ function f() {
2121
f(); // cleanup!
2222
```
2323

24-
...Or when there's a `throw`, like here:
24+
...O quando si presenta un `throw`, come:
2525

2626
```js run
2727
function f() {
@@ -44,4 +44,4 @@ function f() {
4444
f(); // cleanup!
4545
```
4646

47-
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.
47+
È `finally` che garantisce la pulizia qui. Se inseriamo del codice alla fine di `f`, in queste situazioni, non verrà eseguito.
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
importance: 5
1+
importanza: 5
22

33
---
44

5-
# Finally or just the code?
5+
# Finally o solamente il codice?
66

7-
Compare the two code fragments.
7+
Confronta i due frammenti di codice.
88

9-
1. The first one uses `finally` to execute the code after `try..catch`:
9+
1. Il primo utilizza `finally` per eseguire il codice dopo `try..catch`:
1010

1111
```js
1212
try {
13-
work work
13+
lavoro lavoro
1414
} catch (e) {
15-
handle errors
15+
gestisci gli errori
1616
} finally {
1717
*!*
18-
cleanup the working space
18+
ripulisci lo spazio di lavoro
1919
*/!*
2020
}
2121
```
22-
2. The second fragment puts the cleaning right after `try..catch`:
22+
2. Il secondo posiziona la puliza subito dopo il `try..catch`:
2323

2424
```js
2525
try {
26-
work work
26+
lavoro lavoro
2727
} catch (e) {
28-
handle errors
28+
gestisci gli errori
2929
}
3030
3131
*!*
32-
cleanup the working space
32+
ripulisci lo spazio di lavoro
3333
*/!*
3434
```
3535

36-
We definitely need the cleanup after the work, doesn't matter if there was an error or not.
36+
Abbiamo decisamente bisogno di ripulire dopo il lavoro, sia che si verifichi un errore o meno.
3737

38-
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.
38+
Esiste un vantaggio nell'usare `finally` o ambedue i frammenti di codice sono equivalenti? Se c'è qualche vantaggio, allora fornisci un esempio di quanto sia importante.

1-js/10-error-handling/2-custom-errors/1-format-error/solution.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ class FormatError extends SyntaxError {
66
}
77
}
88

9-
let err = new FormatError("formatting error");
9+
let err = new FormatError("errore di formattazione");
1010

11-
alert( err.message ); // formatting error
11+
alert( err.message ); // errore di formattazione
1212
alert( err.name ); // FormatError
1313
alert( err.stack ); // stack
1414

15-
alert( err instanceof SyntaxError ); // true
15+
alert( err instanceof SyntaxError ); // vero
1616
```

1-js/10-error-handling/2-custom-errors/1-format-error/task.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ importance: 5
22

33
---
44

5-
# Inherit from SyntaxError
5+
# Eredita da SyntaxError
66

7-
Create a class `FormatError` that inherits from the built-in `SyntaxError` class.
7+
Crea una classe `FormatError` che eredita dalla classe incorporata `SyntaxError`.
88

9-
It should support `message`, `name` and `stack` properties.
9+
Dovrebbe supportare le proprietà `message`, `name` e `stack`.
1010

1111
Usage example:
1212

1313
```js
1414
let err = new FormatError("formatting error");
1515

16-
alert( err.message ); // formatting error
16+
alert( err.message ); // Errore nella formattazione
1717
alert( err.name ); // FormatError
1818
alert( err.stack ); // stack
1919

20-
alert( err instanceof FormatError ); // true
21-
alert( err instanceof SyntaxError ); // true (because inherits from SyntaxError)
20+
alert( err instanceof FormatError ); // vero
21+
alert( err instanceof SyntaxError ); // vero (poiché eredita SyntaxError)
2222
```

0 commit comments

Comments
 (0)