tryExcept<Err extends Object, R> static method

Either<Err, R> tryExcept<Err extends Object, R>(
  1. R fnR()
)

Constructs a new Either from a function that might throw

simplified version of Either.tryCatch

final fileOrError = Either.tryExcept<FileError>(() => /* maybe throw */);

Implementation

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