Execute the provided callback, wrapping the return value in Ok or Err(error) if there is an exception.
Ok
Err(error)
const aSuccessfulOperation = () => 2 + 2;const anOkResult = Result.tryOr('Oh noes!!1', () => { aSuccessfulOperation()}); // => Ok(4)const thisOperationThrows = () => throw new Error('Bummer');const anErrResult = Result.tryOr('Oh noes!!1', () => { thisOperationThrows();}); // => Err('Oh noes!!1') Copy
const aSuccessfulOperation = () => 2 + 2;const anOkResult = Result.tryOr('Oh noes!!1', () => { aSuccessfulOperation()}); // => Ok(4)const thisOperationThrows = () => throw new Error('Bummer');const anErrResult = Result.tryOr('Oh noes!!1', () => { thisOperationThrows();}); // => Err('Oh noes!!1')
The error value in case of an exception
The callback to try executing
Execute the provided callback, wrapping the return value in
Ok
orErr(error)
if there is an exception.