error_handle.rs 518 B

123456789101112131415161718192021222324252627282930
  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. cx.render(rsx! {
  21. h1 {
  22. "{x}"
  23. }
  24. })
  25. }