Promise.try(callback, ...args) calls callback(...args)right away and returns a promise. A returned value fulfills the promise, a returned promise is followed, and a thrown error rejects it. So one .catch() handles both sync and async errors.
Remember
Promise.try(fn, ...args)
fn returns 5 → fulfilled promise (5)
fn returns promise → follows that promise
fn throws → rejected promise
fn runs → right now, not later
Promise.resolve().then(fn) → fn runs LATER
Syntax
Pass the function first. Every value after it is handed to the function as an argument.
Arguments follow the function.Promise.try(add, 2, 3) calls add(2, 3). You do not need () => add(2, 3).
A plain return value is fulfilled.add returns 5, so fromSync is a promise fulfilled with 5, even though nothing async happened.
An async function works too.addLater returns a promise. Promise.try() follows it, so the result is 9, not a promise inside a promise.
Example 3 — One catch() for Sync and Async Errors
This helper throws for a bad id but rejects for a missing item. Promise.try() sends both failures to one handler.
JavaScript
function loadItem(id) {
if (typeof id !== 'number') {
throw new TypeError('id must be a number');
}
if (id > 100) {
return Promise.reject(new Error('Item ' + id + ' not found'));
}
return Promise.resolve('Item ' + id);
}
async function run() {
for (const id of [7, 'seven', 500]) {
await Promise.try(loadItem, id)
.then((item) => console.log('ok: ' + item))
.catch((error) => console.log(error.name + ': ' + error.message));
}
console.log('all done');
}
run();
ok: Item 7
TypeError: id must be a number
Error: Item 500 not found
all done
How It Works
Two ways to fail.loadItem throws for the string "seven", but returns a rejected promise for 500. Mixed styles like this are common in real code.
One handler covers both. Both the sync TypeError and the async rejection reach the same .catch(), which prints the error name and message.
Take turns.await inside the loop finishes one id before the next starts, so all done is printed last.
Compatibility
Browser & Runtime Support
Promise.try() is part of ES2025.
✓ Newest · ES2025
Promise.try()
Chrome 128+, Edge 128+, Firefox 134+, and Safari 18.2+. The examples were run on Node.js 24. Not in Internet Explorer.
NewLatest browsers only
Google ChromeChrome 128+
Supported
Mozilla FirefoxFirefox 134+
Supported
Apple SafariSafari 18.2+
Supported
Microsoft EdgeEdge 128+
Supported
Node.jsRecent versions · tested on 24
Supported
DenoRecent versions
Supported
Internet ExplorerNo support
Not supported
Promise.try()Latest browsers
Bottom line: Feature-detect with typeof Promise.try === "function". Fallback: new Promise((resolve) => resolve(callback())) also runs the callback at once.
Frequently Asked Questions
It calls your function at once and returns a promise. A return value fulfills it, a returned promise is followed, and a thrown error rejects it.
Right away, before Promise.try() returns. Only the then(), catch(), and finally() callbacks run later. Promise.resolve().then(fn) is different: it runs fn later.
It gives the same result, because an error thrown in the executor rejects the promise. Promise.try() is shorter and passes arguments for you: Promise.try(fn, a, b).
No. An async function already turns a throw into a rejection. Promise.try() helps with normal functions that might throw or might return a promise.
It is ES2025: Chrome 128, Edge 128, Firefox 134, Safari 18.2, and current Node.js. Older browsers can use new Promise(function (resolve) { resolve(fn()); }) instead.