catching<T> static method

Result<T, Exception> catching<T>(
  1. T action()
)

Executes a function and catches any exceptions, returning them as failures

Implementation

static Result<T, Exception> catching<T>(T Function() action) {
  try {
    return Result.success(action());
  } on Exception catch (e) {
    return Result.failure(e);
  }
}