From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../global_objects/syntaxerror/index.html | 133 +++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/syntaxerror/index.html (limited to 'files/fr/web/javascript/reference/global_objects/syntaxerror') diff --git a/files/fr/web/javascript/reference/global_objects/syntaxerror/index.html b/files/fr/web/javascript/reference/global_objects/syntaxerror/index.html new file mode 100644 index 0000000000..2f362a9467 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/syntaxerror/index.html @@ -0,0 +1,133 @@ +--- +title: SyntaxError +slug: Web/JavaScript/Reference/Objets_globaux/SyntaxError +tags: + - Error + - JavaScript + - Object + - Reference + - SyntaxError +translation_of: Web/JavaScript/Reference/Global_Objects/SyntaxError +--- +
{{JSRef}}
+ +

L'objet SyntaxError représente une erreur qui se produit lors de l'interprétation d'un code dont la syntaxe est invalide.

+ +

Description

+ +

Une exception SyntaxError est levée lorsque le moteur JavaScript rencontre des entités lexicales invalide ou dans un ordre invalide par rapport à la grammaire du langage.

+ +

Syntaxe

+ +
new SyntaxError([message[, nomFichier[, numLigne]]])
+ +

Paramètres

+ +
+
message{{optional_inline}}
+
Une description, lisible par un humain, de l'erreur.
+
nomFichier {{optional_inline}}{{non-standard_inline}}
+
Le nom du fichier contenant le code provoquant l'erreur.
+
numLigne {{optional_inline}}{{non-standard_inline}}
+
Le numéro de la ligne du code qui a provoqué l'exception.
+
+ +

Propriétés

+ +
+
{{jsxref("SyntaxError.prototype")}}
+
Cette méthode permet d'ajouter des propriétés aux instance de SyntaxError.
+
+ +

Méthodes

+ +

L'objet global SyntaxError ne contient pas de méthodes directes. En revanche, il hérite de méthodes grâce à sa chaîne de prototypes.

+ +

Instances de SyntaxError

+ +

Propriétés

+ +
{{page('/fr/docs/Web/JavaScript/Reference/Objets_globaux/SyntaxError/prototype', 'Propriétés')}}
+ +

Méthodes

+ +
{{page('/fr/docs/Web/JavaScript/Reference/Objets_globaux/SyntaxError/prototype', 'Méthodes')}}
+ +

Exemples

+ +

Intercepter une exception SyntaxError

+ +
try {
+  eval('toto truc');
+} catch (e) {
+  console.log(e instanceof SyntaxError); // true
+  console.log(e.message);                // "missing ; before statement"
+  console.log(e.name);                   // "SyntaxError"
+  console.log(e.fileName);               // "Scratchpad/1"
+  console.log(e.lineNumber);             // 1
+  console.log(e.columnNumber);           // 4
+  console.log(e.stack);                  // "@Scratchpad/1:2:3\n"
+}
+
+ +

Créer une exception SyntaxError

+ +
try {
+  throw new SyntaxError('Coucou', 'unFichier.js', 10);
+} catch (e) {
+  console.log(e instanceof SyntaxError); // true
+  console.log(e.message);                // "Coucou"
+  console.log(e.name);                   // "SyntaxError"
+  console.log(e.fileName);               // "unFichier.js"
+  console.log(e.lineNumber);             // 10
+  console.log(e.columnNumber);           // 0
+  console.log(e.stack);                  // "@Scratchpad/2:11:9\n"
+}
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpécificationStatutCommentaires
{{SpecName('ES3')}}{{Spec2('ES3')}}Définition initiale.
{{SpecName('ES5.1', '#sec-15.11.6.4', 'SyntaxError')}}{{Spec2('ES5.1')}} 
{{SpecName('ES6', '#sec-native-error-types-used-in-this-standard-syntaxerror', 'SyntaxError')}}{{Spec2('ES6')}} 
{{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard-syntaxerror', 'SyntaxError')}}{{Spec2('ESDraft')}} 
+ +

Compatibilité des navigateurs

+ +
+ + +

{{Compat("javascript.builtins.SyntaxError")}}

+
+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf