ZIO<R, E, A>.tryCatch constructor
ZIO<R, E, A>.tryCatch (
- FutureOr<
A> f(), - E onError(
- dynamic error,
- StackTrace stackTrace
Create a EIO from the given function f
, which may throw an exception.
If the function throws an exception, the EIO will fail with the result of
calling onError
with the exception and stack trace.
Otherwise, the EIO will succeed with the result.
Implementation
factory ZIO.tryCatch(
FutureOr<A> Function() f,
E Function(dynamic error, StackTrace stackTrace) onError,
) =>
ZIO.from(
(ctx) => fromThrowable(
f,
onError: (e, s) => Failure(onError(e, s)),
),
);