Either<L, R>.tryCatch constructor
Either<L, R>.tryCatch (
- R run(),
- L onError(
- Object o,
- StackTrace s
Try to execute run
. If no error occurs, then return Right.
Otherwise return Left containing the result of onError
.
Implementation
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));
}
}