Skip to main content

Promise.try

Less than 1 minutefeaturees-proposal

Promise.tryopen in new window

Note

This proposal is dead and will be removed from the next major Core-JS version.

Module

esnext.promise.tryopen in new window

Types

interface PromiseConstructor {
  try<T>(callbackfn: () => T | Promise<T>): Promise<T>;
}

Entry points

core-js/proposals/promise-try
core-js(-pure)/full/promise/try

Example

Exampleopen in new window:

Promise.try(() => 42).then((it) => console.log(`Promise, resolved as ${it}`));

Promise.try(() => {
  throw 42;
}).catch((it) => console.log(`Promise, rejected as ${it}`));