Learn how to use the catch() method of Promise instances to handle rejections and chain calls to other promise methods. See syntax, parameters, return value, description, examples, and browser compatibility of catch().
La méthode then() permet de planifier l'exécution des fonctions de rappel pour gérer la résolution d'une promesse (que ce soit une réussite ou un échec).
https://www.w3schools.com › jsref › jsref_promise_then.asp
JavaScript Promise then() Method - W3SchoolsDescription. The then() method provides two callbacks: One funtion to run when a promise is fulfilled and one funtion to run when a promise is rejected. Syntax. promise.then (fulfilled (), rejected ()) Parameters. Return Value. Promise Tutorial. catch () finally () then () Browser Support. then() is an ECMAScript6 (ES6) feature.
La méthode catch() est utile pour gérer les cas d'erreur en cas de compositions de plusieurs promesses. Elle renvoie elle-même une promesse et peut donc être utilisée lorsqu'on chaîne des promesses, à l'instar de la méthode sœur qu'est Promise.prototype.then().
https://fr.javascript.info › task › then-vs-catch
Promesse: then contre catch - JavaScriptPromesse: then contre catch. Ces fragments de code sont-ils égaux? En d’autres termes, se comportent-ils de la même manière en toutes circonstances, pour toutes les fonctions gestionnaires? promise.then( f1).catch( f2); Contre: promise.then( f1, f2); solution.
https://javascript.info › promise-chaining
Promises chaining - The Modern JavaScript TutorialIf a .then (or catch/finally, doesn’t matter) handler returns a promise, the rest of the chain waits until it settles. When it does, its result (or error) is passed further. Here’s a full picture:
https://javascript.info › promise-error-handling
Error handling with promises - The Modern JavaScript TutorialLearn how to use .catch to handle errors in promise chains, and how to rethrow or stop the execution. See examples of implicit try..catch, rejection events and unhandled rejections.
https://masteringjs.io › tutorials › fundamentals › then
The Promise then() Function in JavaScript - Mastering JSThe Promise#catch() function in JavaScript is a convenient shorthand for .then(). Calling .catch(onRejected) is syntactic sugar for .then(null, onRejected).
https://masteringjs.io › tutorials › fundamentals › catch
The Promise `catch()` Function in JavaScript - Mastering JSThe catch() function tells JavaScript what function to call if the promise is rejected: const p = Promise.reject(new Error ('Oops!')); p.catch(err => { err.message; // 'Oops!'}); With Promise Chaining. The major benefit of .catch() is that you can catch errors that occurred anywhere in a promise chain. const p = Promise.resolve('Na ...
https://www.w3schools.com › Js › js_promise.asp
JavaScript Promises - W3SchoolsHere is how to use a Promise: myPromise.then ( function (value) { /* code if successful */ }, function (error) { /* code if some error */ } ); Promise.then () takes two arguments, a callback for success and another for failure. Both are optional, so you can add a callback for success or failure only.