JavaScript Promise try() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Static method

Definition

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.

JavaScript
Promise.try(callback)
Promise.try(callback, arg1, arg2)
CallWhat it does
Promise.try(callback)Call callback() now and wrap the outcome in a promise.
Promise.try(callback, ...args)Call callback(...args). No extra arrow function is needed.
Promise.try(fn).catch(handler)Handle a sync throw and an async rejection together.

Added in ES2025. Feature-detect with typeof Promise.try === "function".

Library declarations
JavaScript
Promise.try(callback, ...args)   // returns a Promise

// callback runs synchronously, before try() returns

Parameters

ParameterDescription
callbackRequired. The function to run. It can return a value, return a promise, or throw. It can be async.
...argsOptional. Values passed to callback as its arguments, in order.

Return Value

Return ValueDescription
Promise (fulfilled)The callback returned a value, or a promise that was fulfilled.
Promise (rejected)The callback threw, or returned a promise that was rejected.

JavaScript Examples

Example 1 — A Sync Throw Becomes a Rejection

Call one function plainly with try/catch, then through Promise.try(), where the error becomes a rejection.

JavaScript
function readConfig(text) {
  console.log('readConfig is running');
  if (!text) {
    throw new Error('Config is empty');
  }
  return text.toUpperCase();
}

try {
  readConfig('');
} catch (error) {
  console.log('plain call threw: ' + error.message);
}

Promise.try(readConfig, '').catch((error) => {
  console.log('Promise.try rejected: ' + error.message);
});

console.log('after Promise.try');
Try It Yourself

How It Works

  1. The function runs right now. readConfig is running prints again before after Promise.try, so the call is not delayed.
  2. A plain call throws. Without help, the error escapes from readConfig('') and needs a try/catch block.
  3. The same throw becomes a value. Promise.try() catches it and returns a rejected promise, so .catch() prints the message last.

Example 2 — Return Values and Arguments

Run a normal function and an async function through Promise.try(), with arguments.

JavaScript
function add(a, b) {
  return a + b;
}

async function addLater(a, b) {
  return a + b;
}

const fromSync = Promise.try(add, 2, 3);
const fromAsync = Promise.try(addLater, 4, 5);

console.log(fromSync instanceof Promise);
console.log(fromAsync instanceof Promise);

fromSync.then((value) => console.log('sync result: ' + value));
fromAsync.then((value) => console.log('async result: ' + value));
Try It Yourself

How It Works

  1. Arguments follow the function. Promise.try(add, 2, 3) calls add(2, 3). You do not need () => add(2, 3).
  2. A plain return value is fulfilled. add returns 5, so fromSync is a promise fulfilled with 5, even though nothing async happened.
  3. 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();
Try It Yourself

How It Works

  1. 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.
  2. One handler covers both. Both the sync TypeError and the async rejection reach the same .catch(), which prints the error name and message.
  3. Take turns. await inside the loop finishes one id before the next starts, so all done is printed last.

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.

New Latest browsers only
Google Chrome Chrome 128+
Supported
Mozilla Firefox Firefox 134+
Supported
Apple Safari Safari 18.2+
Supported
Microsoft Edge Edge 128+
Supported
Node.js Recent versions · tested on 24
Supported
Deno Recent versions
Supported
Internet Explorer No 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.

Next: Promise.withResolvers()

Get a promise together with the functions that settle it, so you can finish it from outside.

withResolvers() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful