ZIO<R, E, A>.tryCatch constructor

ZIO<R, E, A>.tryCatch(
  1. FutureOr<A> f(),
  2. E onError(
    1. dynamic error,
    2. 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)),
      ),
    );