pub fn set_spawn_panic_handler(
handler: impl FnMut(TaskPanicError) + Send + 'static,
)Expand description
Set a handler that is called when spawn tasks panic, replacing previous.
On panic the tasks spawn, poll_spawn and spawn_wait log an error, notifies the handler and otherwise ignores the panic.
The handler is set for the process lifetime, only one handler can be set per app. The handler is called inside the same LocalContext
and thread the task that panicked was called in.
task::set_spawn_panic_handler(|p| {
if cfg!(debug_assertions) {
inspect_spawn_panic(p);
return;
}
// APP sets a handler that resumes panic in app thread
UPDATES
.run_hn_once(hn_once!(|_| {
std::panic::resume_unwind(p.payload);
}))
.perm();
});The example above shows how to set a handler intercept the panic, it also shows what the APP default handler does.
ยงDefault
Default handler outside apps does nothing. The APP builder sets a handler that resumes panic in
the app thread, you can override this on app init, or any time after it is build.