Recovering From Errors
When a ZIO effect fails, we have several strategies for bringing it back to a successful result. Some operators work on the typed error channel; others reach into the full Cause graph to handle defects and interruptions as well.
- Catching recovers from typed failures, defects, interruptions, and the full
Causegraph using operators such ascatchAll,catchSome,catchAllCause, andcatchAllDefect. - Fallback provides an alternative effect or value when an effect fails, using
orElse,orElseFail,orElseSucceed, and related combinators. - Folding handles both success and failure in one step with
fold,foldZIO,foldCause, andfoldCauseZIO— the primitive all other ZIO error operators build on. - Retrying re-runs a failing effect according to a
Schedulepolicy, with configurable delays, attempt limits, and fallback strategies. - Timing Out bounds effect execution time with timeout combinators that safely interrupt the effect and optionally convert the result to a typed failure.
- Sandboxing exposes the full
Causegraph — including defects and interruptions — usingsandbox,unsandbox, andsandboxWith, so any recovery operator can reach them.