The promise is rejected with the thrown error. You do not need to try/catch inside the executor; the Promise constructor catches thrown errors and rejects automatically.
What happens if the promise executor throws an error in JavaScript?
More FAQs in Creating Promises in JavaScript
Use new Promise((resolve, reject) => { ... }). The executor runs immediately. Call resolve(value) to fulfill or reject(reason) to reject. For already-settled promises, use Promise.resolve(value) or Promise.reject(reason).
Immediately and synchronously, when the promise is created. The executor is not deferred. But resolve/reject can be called asynchronously (inside a setTimeout, event handler, etc.).
Creating an already-fulfilled promise. Use it when you have a value but need a promise (e.g., returning from a function that sometimes does sync work). Example: if (cached) return Promise.resolve(cached); else return fetch(url);
Still have questions?
Browse all our FAQs or reach out to our support team
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.