Skip to content

Commit de10cd3

Browse files
authored
Merge pull request #191 from otmon76/1.10.2
Custom errors, extending Error
2 parents 43b6afc + 4c20fbc commit de10cd3

File tree

3 files changed

+174
-174
lines changed

3 files changed

+174
-174
lines changed
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
```js run untrusted
2-
class FormatError extends SyntaxError {
3-
constructor(message) {
4-
super(message);
2+
class ChybaFormátu extends SyntaxError {
3+
constructor(zpráva) {
4+
super(zpráva);
55
this.name = this.constructor.name;
66
}
77
}
88

9-
let err = new FormatError("formatting error");
9+
let chyba = new ChybaFormátu("chyba formátování");
1010

11-
alert( err.message ); // formatting error
12-
alert( err.name ); // FormatError
13-
alert( err.stack ); // stack
11+
alert( chyba.message ); // chyba formátování
12+
alert( chyba.name ); // ChybaFormátu
13+
alert( chyba.stack ); // zásobník
1414

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

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

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

33
---
44

5-
# Inherit from SyntaxError
5+
# Dědění ze třídy SyntaxError
66

7-
Create a class `FormatError` that inherits from the built-in `SyntaxError` class.
7+
Vytvořte třídu `ChybaFormátu`, která je zděděna ze zabudované třídy `SyntaxError`.
88

9-
It should support `message`, `name` and `stack` properties.
9+
Měla by podporovat vlastnosti `message`, `name` a `stack`.
1010

11-
Usage example:
11+
Příklad použití:
1212

1313
```js
14-
let err = new FormatError("formatting error");
14+
let chyba = new ChybaFormátu("chyba formátování");
1515

16-
alert( err.message ); // formatting error
17-
alert( err.name ); // FormatError
18-
alert( err.stack ); // stack
16+
alert( chyba.message ); // chyba formátování
17+
alert( chyba.name ); // ChybaFormátu
18+
alert( chyba.stack ); // zásobník
1919

20-
alert( err instanceof FormatError ); // true
21-
alert( err instanceof SyntaxError ); // true (because inherits from SyntaxError)
20+
alert( chyba instanceof ChybaFormátu ); // true
21+
alert( chyba instanceof SyntaxError ); // true (protože je zděděna ze SyntaxError)
2222
```

0 commit comments

Comments
 (0)