I'm trying to catch panics in a multi-thread GUI program. I want to get a backtrace of the panicking thread, log it (there's no text console) and then tell all the other threads to shut down cleanly.
So I tried catch_unwind and backtrace.
Catching the panic works, but it seems to be caught too late. When I get the backtrace, it's a backtrace of the internals of the panic system, not the program with the problem. This is useless.
What's the right way to do this?
Backtrace: Backtrace [
{ fn: "playground::main", file: "./src/main.rs", line: 19 },
{ fn: "core::ops::function::FnOnce::call_once", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/ops/function.rs", line: 250 },
{ fn: "std::sys_common::backtrace::__rust_begin_short_backtrace", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys_common/backtrace.rs", line: 121 },
{ fn: "std::rt::lang_start::{{closure}}", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/rt.rs", line: 166 },
{ fn: "core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/core/src/ops/function.rs", line: 287 },
{ fn: "std::panicking::try::do_call", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs", line: 483 },
{ fn: "std::panicking::try", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs", line: 447 },
{ fn: "std::panic::catch_unwind", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panic.rs", line: 140 },
{ fn: "std::rt::lang_start_internal::{{closure}}", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/rt.rs", line: 148 },
{ fn: "std::panicking::try::do_call", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs", line: 483 },
{ fn: "std::panicking::try", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panicking.rs", line: 447 },
{ fn: "std::panic::catch_unwind", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/panic.rs", line: 140 },
{ fn: "std::rt::lang_start_internal", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/rt.rs", line: 148 },
{ fn: "std::rt::lang_start", file: "/rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/rt.rs", line: 165 },
{ fn: "main" },
{ fn: "__libc_start_main" }, { fn: "_start" }]