Skip to main content

catch_user_panic

Function catch_user_panic 

Source
pub fn catch_user_panic<F: FnOnce()>(site: &str, f: F)
Expand description

Run f and swallow any panic it produces.

On panic, writes a best-effort diagnostic to stderr identifying the callback site and the panic message (when the payload is a &str or String). The diagnostic write is itself wrapped in catch_unwind so an allocator failure or broken stderr can never propagate out.

AssertUnwindSafe is required because trait objects are not generally UnwindSafe and we accept the user’s responsibility for their own state consistency on panic.