Skip to main content

scoped_panic_hook/
lib.rs

1//! # Catching panics
2//!
3//! Just use
4//!
5//! ```rust
6//! let result = scoped_panic_hook::catch_panic(|| panic!("Oopsie!"));
7//!
8//! if let Err(panic) = result {
9//!     eprintln!("{}", panic.display_with_backtrace());
10//! }
11//! ```
12//!
13//! Any panic which happens inside closure supplied to [`catch_panic`]
14//! will be caught
15//!
16//! # Using manual panic hooks
17//!
18//! In case you want to do something nontrivial, you can analyze panics manually
19//!
20//! ```rust
21//! let mut counter = 0;
22//!
23//! let _ = scoped_panic_hook::hook::catch_unwind_with_scoped_hook(
24//!     |_| { counter += 1; scoped_panic_hook::hook::NextHook::PrevInstalledHook },
25//!     || panic!("Oopsie!")
26//! );
27//!
28//! println!("Caught panics: {counter}");
29//! ```
30#![cfg_attr(
31    nightly,
32    feature(panic_update_hook),
33    feature(panic_can_unwind),
34    feature(panic_backtrace_config)
35)]
36// `core::panicking::panic_nounwind` in tests
37#![cfg_attr(all(nightly, test), allow(internal_features), feature(panic_internals))]
38
39/// Raw API for setting up scoped panic hooks
40pub mod hook;
41/// Panic capture types and functions,
42/// including some with finer tuned functionality
43pub mod panic;
44
45pub use panic::{Panic, catch_panic};