-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial translation for
TypeError()
constructor (#5549)
* Initial translation for TypeError constructor * single quotes/nitpicking Co-authored-by: Carolyn Wu <[email protected]>
- Loading branch information
1 parent
4daa50a
commit a3ffb64
Showing
1 changed file
with
73 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
files/fr/web/javascript/reference/global_objects/typeerror/typeerror/index.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
--- | ||
title: Constructeur TypeError() | ||
slug: Web/JavaScript/Reference/Global_Objects/TypeError/TypeError | ||
translation_of: Web/JavaScript/Reference/Global_Objects/TypeError/TypeError | ||
browser-compat: javascript.builtins.TypeError.TypeError | ||
--- | ||
{{JSRef}} | ||
|
||
Le constructeur **`TypeError()`** permet de créer un objet représentant une erreur qui se produit lorsqu'une opération n'a pu être réalisée, généralement (mais pas toujours) parce qu'une valeur n'était pas du type attendu. | ||
|
||
## Syntaxe | ||
|
||
```js | ||
new TypeError() | ||
new TypeError(message) | ||
new TypeError(message, nomFichier) | ||
new TypeError(message, nomFichier, numeroLigne) | ||
``` | ||
|
||
### Paramètres | ||
|
||
- `message` {{optional_inline}} | ||
- : Une description de l'erreur, compréhensible par un humain. | ||
- `nomFichier` {{optional_inline}} | ||
- : Le nom du fichier qui contient le code qui a déclenché l'exception. | ||
- `numeroLigne` {{optional_inline}} | ||
- : Le numéro de la ligne du code qui a déclenché l'exception. | ||
|
||
## Exemples | ||
|
||
### Intercepter une exception `TypeError` | ||
|
||
```js | ||
try { | ||
null.f(); | ||
} catch (e) { | ||
console.log(e instanceof TypeError); // true | ||
console.log(e.message); // "null has no properties" | ||
console.log(e.name); // "TypeError" | ||
console.log(e.fileName); // "Scratchpad/1" | ||
console.log(e.lineNumber); // 2 | ||
console.log(e.columnNumber); // 2 | ||
console.log(e.stack); // "@Scratchpad/2:2:3\n" | ||
} | ||
``` | ||
|
||
### Créer une exception `TypeError` | ||
|
||
```js | ||
try { | ||
throw new TypeError('Coucou', 'unFichier.js', 10); | ||
} catch (e) { | ||
console.log(e instanceof TypeError); // true | ||
console.log(e.message); // "Coucou" | ||
console.log(e.name); // "TypeError" | ||
console.log(e.fileName); // "unFichier.js" | ||
console.log(e.lineNumber); // 10 | ||
console.log(e.columnNumber); // 0 | ||
console.log(e.stack); // "@Scratchpad/2:2:9\n" | ||
} | ||
``` | ||
|
||
## Spécifications | ||
|
||
{{Specifications}} | ||
|
||
## Compatibilité des navigateurs | ||
|
||
{{Compat}} | ||
|
||
## Voir aussi | ||
|
||
- [`Error`](/fr/docs/Web/JavaScript/Reference/Global_Objects/Error) |