dioxus/examples/error_handle.rs

31 lines
518 B
Rust
Raw Normal View History

2023-11-08 00:24:07 +00:00
use dioxus::{core::CapturedError, prelude::*};
fn main() {
dioxus_desktop::launch(App);
}
#[component]
fn App(cx: Scope) -> Element {
cx.render(rsx! {
2023-11-08 00:24:07 +00:00
ErrorBoundary {
handle_error: |error: CapturedError| rsx! {"Found error {error}"},
DemoC {
x: 1
}
}
2022-11-16 09:13:39 +00:00
})
}
#[component]
fn DemoC(cx: Scope, x: i32) -> Element {
2023-11-08 00:24:07 +00:00
let result = Err("Error");
result.throw()?;
2022-11-16 09:13:39 +00:00
cx.render(rsx! {
h1 {
2023-11-08 00:24:07 +00:00
"{x}"
2022-11-16 09:13:39 +00:00
}
})
}