Wrapper for try/catch.
try
catch
This functions tries to run a function and silences the throws by wrapping it with a try/catch and returning undefined instead.
throw
try/catch
undefined
const willFail = () => { throw new Error("fail");};const safeWillFail = attempt(willFail);safeWillFail(); // undefined Copy
const willFail = () => { throw new Error("fail");};const safeWillFail = attempt(willFail);safeWillFail(); // undefined
Type of the arguments of the function to be wrapped.
Function to be wrapped.
Function wrapped in try/catch.
Rest
Wrapper for
try
/catch
.Remarks
This functions tries to run a function and silences the
throw
s by wrapping it with atry/catch
and returningundefined
instead.Example