Either<L, R>.tryCatch constructor Null safety

Either<L, R>.tryCatch(
  1. R run(
    1. L onError(
      1. Object o,
      2. StackTrace s

    Try to execute run. If no error occurs, then return Right. Otherwise return Left containing the result of onError.


    factory Either.tryCatch(
        R Function() run, L Function(Object o, StackTrace s) onError) {
      try {
        return Either.of(run());
      } catch (e, s) {
        return Either.left(onError(e, s));