guard<S> function
Executes the function in a protected context. func
is called inside a try catch block. If the result does not
catch, then return value func
returned inside an Ok. If func
throws, then the thrown value is returned
inside an Err.
Implementation
@pragma("vm:prefer-inline")
Result<S, Object> guard<S>(S Function() func) {
assert(S is! Result, "Use guardResult instead");
try {
return Ok(func());
} catch (e) {
return Err(e);
}
}