跳至主要內容

Promise.try

小于 1 分钟featurees-proposal

Promise.tryopen in new window

注意

该提案已被撤回,并将从下一个主要的 Core-JS 版本中删除。

模块

esnext.promise.tryopen in new window

类型

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

入口点

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

示例

示例open 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}`));