FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    error_boundary

    function · ferroui-view · v0.5.0

    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.

    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

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.