# error_boundary

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-view/error_boundary/function-error_boundary/

**function** · [`ferroui-view`](/docs/0.5.0/api/ferroui-view/) · v0.5.0

```rust
fn error_boundary(child: impl Fn() -> crate::element::Element + 'static, fallback: impl Fn(ErrorInfo) -> crate::element::Element + 'static) -> crate::element::Element
```

A component that mounts `child()`; when a run of a component below it
panics (its first run or a later one), the boundary takes the child tree
out (disposing its owner) and shows `fallback(info)` instead of ending the
application. `info.reset()` mounts the child again.

```ignore
error_boundary(
    || rsx! { Report {} },
    |info| rsx! {
        StackPanel {
            TextBlock { text: format!("The report failed: {}", info.message()) }
            Button { on_click: move |_| info.reset(), "Try again" }
        }
    },
)
```

The nearest boundary catches: a boundary inside the child of another
catches the panics below it, and a panic of a fallback goes to the
boundary above. What is guarded is the function of each component below
(`rerender`, `#[component(rerender)]`), `child` itself included; the
handlers and effects of the controls are not. A caught panic is reported
as `Diagnostic::ErrorCaught`. The panic
hook of the process still runs, so the message of the panic is printed as
usual.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.View/error_boundary.rs#L154)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
