error_handle.rs 490 B

12345678910111213141516171819202122232425262728
  1. use dioxus::{core::CapturedError, prelude::*};
  2. fn main() {
  3. dioxus_desktop::launch(App);
  4. }
  5. #[component]
  6. fn App(cx: Scope) -> Element {
  7. cx.render(rsx! {
  8. ErrorBoundary {
  9. handle_error: |error: CapturedError| rsx! {"Found error {error}"},
  10. DemoC {
  11. x: 1
  12. }
  13. }
  14. })
  15. }
  16. #[component]
  17. fn DemoC(cx: Scope, x: i32) -> Element {
  18. let result = Err("Error");
  19. result.throw()?;
  20. render! {
  21. h1 { "{x}" }
  22. }
  23. }