Takes a callback of any kind (returns or throws, synchronously or asynchronously) and wraps its result in a Promise.
PromiseConstructor.try method | globals module | Bun BuildDocsReferenceGuidesBlogDiscord/Globals/PromiseConstructor/tryMtry BuildDocsReferenceGuidesBlogDiscord /Globals/PromiseConstructor/tryMtry @param callbackFn @param args @returns tryT, A extends any[] = []>(fn: (...args: A) => T | PromiseLikeT>,...args: A): PromiseT>; @param fn @param args @returns
Search the reference...
/
method
PromiseConstructor.trytryT, U extends unknown[]>(callbackFn: (...args: U) => T | PromiseLikeT>,...args: U): PromiseAwaitedT>>;A function that is called synchronously. It can do anything: either return a value, throw an error, or return a promise.
Additional arguments, that will be passed to the callback.
A Promise that is:
Already fulfilled, if the callback synchronously returns a value.Already rejected, if the callback synchronously throws an error.Asynchronously fulfilled or rejected, if the callback returns a promise.Try to run a function and return the result. If the function throws, return the result of the catch function.
The function to run
The arguments to pass to the function. This is similar to setTimeout and avoids the extra closure.
The result of the function or the result of the catch function
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →PromiseConstructor.try method | globals module | Bun,AI智能索引,全网链接索引,智能导航,网页索引
- API documentation for method globals.PromiseConstructor.try | Bun