Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Custom errors, extending Error#191

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
otmon76 merged 1 commit intojavascript-tutorial:masterfromotmon76:1.10.2
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
```js run untrusted
classFormatError extends SyntaxError {
constructor(message) {
super(message);
classChybaFormátu extends SyntaxError {
constructor(zpráva) {
super(zpráva);
this.name = this.constructor.name;
}
}

leterr = newFormatError("formatting error");
letchyba = newChybaFormátu("chyba formátování");

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

alert(err instanceof SyntaxError ); // true
alert(chyba instanceof SyntaxError ); // true
```
20 changes: 10 additions & 10 deletions1-js/10-error-handling/2-custom-errors/1-format-error/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,21 +2,21 @@ importance: 5

---

#Inherit from SyntaxError
#Dědění ze třídy SyntaxError

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

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

Usage example:
Příklad použití:

```js
leterr = newFormatError("formatting error");
letchyba = newChybaFormátu("chyba formátování");

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

alert(err instanceofFormatError ); // true
alert(err instanceof SyntaxError ); // true (because inherits from SyntaxError)
alert(chyba instanceofChybaFormátu ); // true
alert(chyba instanceof SyntaxError ); // true (protože je zděděna ze SyntaxError)
```
Loading

[8]ページ先頭

©2009-2025 Movatter.jp