attempt | WebHare Platform SDKWebHare Platform SDKPreparing search index...@webhare/stdattemptFunction attemptattempt<T>(toTry: Promise<T> | (() => Promise<T>)): Promise<T | undefined>Attempt to run code that may throw. If it throws anything, the fallback is returned This allows you to replace: let url; try { url = new URL(inurl);} catch (e) { return null;}```with Copy const url = attempt(() => new URL(inurl)); Copy Type ParametersTParameterstoTry: Promise<T> | (() => Promise<T>)Returns Promise<T | undefined>attempt<T, F>( toTry: Promise<T> | (() => Promise<T>), fallback: F,): Promise<T | F>Attempt to run code that may throw. If it throws anything, the fallback is returned This allows you to replace: let url; try { url = new URL(inurl);} catch (e) { return null;}```with Copy const url = attempt(() => new URL(inurl)); Copy Type ParametersTFParameterstoTry: Promise<T> | (() => Promise<T>)fallback: FReturns Promise<T | F>attempt<T>(toTry: () => T): T | undefinedAttempt to run code that may throw. If it throws anything, the fallback is returned This allows you to replace: let url; try { url = new URL(inurl);} catch (e) { return null;}```with Copy const url = attempt(() => new URL(inurl)); Copy Type ParametersTParameterstoTry: () => TReturns T | undefinedattempt<T, F>(toTry: () => T, fallback: F): T | FAttempt to run code that may throw. If it throws anything, the fallback is returned This allows you to replace: let url; try { url = new URL(inurl);} catch (e) { return null;}```with Copy const url = attempt(() => new URL(inurl)); Copy Type ParametersTFParameterstoTry: () => Tfallback: FReturns T | FSettingsMember VisibilityProtectedInheritedThemeOSLightDarkWebHare Platform SDKLoading...
Attempt to run code that may throw. If it throws anything, the fallback is returned
This allows you to replace:
const url = attempt(() => new URL(inurl));