[][src]Function maybe_unwind::set_hook

pub fn set_hook()

Registers the custom panic hook so that the panic information can be captured.

This function saves the current panic hook and replaces with a custom hook that captures the panic information caused by closures enclosed in maybe_unwind. If the panic originated outside of maybe_unwind, the saved panic hook is invoked instead.

Note that the panic hook is managed globally and replacing the hook reflects all threads in the application.

Panics

This function panics if it is called from a panicking thread or the global state is poisoned.

Data racing

This function may cause a data race if the panic hook is set from the different thread at the same time. The application must ensure that the all dependencies that may use the custom panic hook set their hooks before calling set_hook, and the panic hook is not changed afterwards.

Example

use maybe_unwind::{maybe_unwind, set_hook};

set_hook();

let res = maybe_unwind(|| { panic!("oops"); });
assert!(res.is_err());