IOEither<L, R>.tryCatch constructor

IOEither<L, R>.tryCatch(
  1. R run(),
  2. L onError(
    1. Object error,
    2. StackTrace stackTrace
    )
)

Converts a Function that may throw to a Function that never throws but returns a Either instead.

Used to handle asynchronous computations that may throw using Either.

Implementation

factory IOEither.tryCatch(R Function() run,
        L Function(Object error, StackTrace stackTrace) onError) =>
    IOEither<L, R>(() {
      try {
        return Right<L, R>(run());
      } catch (error, stack) {
        return Left<L, R>(onError(error, stack));
      }
    });