Région de recherche :

Date :

https://stackoverflow.com › questions › 33445415

JavaScript Promises - reject vs. throw - Stack Overflow

Any time you are inside of a promise callback, you can use throw. However, if you're in any other asynchronous callback, you must use reject. For example, this won't trigger the catch: new Promise(function() {. setTimeout(function() {. throw 'or nah'; // return Promise.reject('or nah'); also won't work. }, 1000);

https://stackoverflow.com › questions › 36652195

javascript - Using throw in promises - Stack Overflow

I would like to create a function that returns a promise and if something throws an error within, it returns promise reject.

https://developer.mozilla.org › fr › docs › Web › JavaScript › Guide › Using_promises

Utiliser les promesses - JavaScript | MDN - MDN Web Docs

Promise.resolve() et Promise.reject() sont des méthodes qui permettent de créer des promesses déjà tenues ou rompues. Promise.all() et Promise.race() sont deux outils de composition qui permettent de mener des opérations asynchrones en parallèle.

https://developer.mozilla.org › fr › docs › Web › JavaScript › Reference › Global_Objects › Promise

Promise - JavaScript | MDN - MDN Web Docs

Les méthodes promise.then(), promise.catch(), et promise.finally() sont utilisées pour associer une action ultérieure à une promesse lorsque celle-ci devient acquittée. La méthode .then() prend deux arguments : le premier est une fonction de rappel ( callback ) pour le cas de résolution de la promesse et le second argument est une ...

https://developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Using_promises

Using promises - JavaScript | MDN - MDN Web Docs

doSomethingElse and doThirdThing can return any value — if they return promises, that promise is first waited until it settles, and the next callback receives the fulfillment value, not the promise itself.

https://javascript.info › promise-error-handling

Error handling with promises - The Modern JavaScript Tutorial

If we throw inside a .then handler, that means a rejected promise, so the control jumps to the nearest error handler. Here’s an example: new Promise((resolve, reject) => { resolve("ok"); }).then((result) => { throw new Error("Whoops!"); // rejects the promise }).catch(alert); // Error: Whoops!

https://www.javascripttutorial.net › promise-error-handling

Promise Error Handling - JavaScript Tutorial

If you throw an error inside the promise, the catch() method will catch it, not the try/catch. If you chain promises, the catch() method will catch errors that occur in any promise. For example:

https://stackoverflow.com › questions › 42167274

javascript - Rethrowing error in promise catch - Stack Overflow

Both .then() and .catch() methods return Promises, and if you throw an Exception in either handler, the returned promise is rejected and the Exception will be caught in the next reject handler. In the following code, we throw an exception in the first .catch(), which is caught in the second .catch() :

https://web.dev › articles › promises

JavaScript Promises: an introduction | Articles - web.dev

Promises have arrived in JavaScript! [Fireworks explode, glittery paper rains from above, the crowd goes wild] At this point you fall into one of these categories: People are cheering around you, but you're not sure what all the fuss is about. Maybe you're not even sure what a "promise" is.

https://medium.com › insiderengineering › mastering-javascript-promises-from-basics-to...

Mastering JavaScript Promises: From Basics to Advanced

Promises were introduced in JavaScript with ES6 in 2015. A Promise is a JavaScript object used for managing asynchronous operations. Promises allow you to write code that continues after...

Mastering JavaScript Promises: From Basics to Advanced