tryCatch<L, R, Err extends Object> static method

Either<L, R> tryCatch<L, R, Err extends Object>(
  1. L onError(
    1. Err err
    ),
  2. R fnR()
)

Constructs a new Either from a function that might throw

Implementation

static Either<L, R> tryCatch<L, R, Err extends Object>(
    L Function(Err err) onError, R Function() fnR) {
  try {
    return Right(fnR());
  } on Err catch (e) {
    return Left(onError(e));
  }
}