Standard built-ins
Promise.try()
Invokes the callback immediately with supplied arguments and resolves or rejects a returned promise using its completion. Not available in the local Node 22.16.0 runtime; the example only tests the fallback.
Formal Syntax & Structure
javascript syntaxjavascript
Promise.try(callback, ...args)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| callback | function | Function to invoke. |
| args | any[] | Arguments forwarded to the callback. |
Return Value
Promise
Promise resolved to return value or rejected with thrown error.
Working Example
Example Snippetjavascript
if (typeof Promise.try === "function") { Promise.try(() => { console.log("call"); throw new Error("oops"); }).catch(e => console.log(e.message)); console.log("after");} else { console.log("Promise.try unavailable"); }