executeProtected<S> function

Result<S, Object> executeProtected<S>(
  1. S func()
)

Executes the function in a protected context. func is called inside a try catch block. If the result is not catch, then return value func returned inside an Ok. If func throws, then the thrown value is returned inside an Err.

Implementation

Result<S,Object> executeProtected<S>(S Function() func) {
  assert(S is! Result, "Use executeProtectedResult instead");
  try {
    return Ok(func());
  } catch (e) {
    return Err(e);
  }
}