Crate scoped_panic_hook

Crate scoped_panic_hook 

Source
Expand description

§Catching panics

Just use

let result = scoped_panic_hook::catch_panic(|| panic!("Oopsie!"));

if let Err(panic) = result {
    eprintln!("{}", panic.display_with_backtrace());
}

Any panic which happens inside closure supplied to catch_panic will be caught

§Using manual panic hooks

In case you want to do something nontrivial, you can analyze panics manually

let mut counter = 0;

let _ = scoped_panic_hook::hook::catch_unwind_with_scoped_hook(
    |_| { counter += 1; scoped_panic_hook::hook::NextHook::PrevInstalledHook },
    || panic!("Oopsie!")
);

println!("Caught panics: {counter}");

Re-exports§

pub use panic::Panic;
pub use panic::catch_panic;

Modules§

hook
Raw API for setting up scoped panic hooks
panic
Panic capture types and functions, including some with finer tuned functionality