tryCatch<T, E, F extends Object> static method
Constructs a new Result from a function that might throw.
Implementation
static Result<T, E> tryCatch<T, E, F extends Object>(
T Function() fn,
E Function(F e) onError,
) {
try {
return Ok(fn());
} on F catch (e) {
return Err(onError(e));
}
}