Skip to main content

set_panic_handler

Function set_panic_handler 

Source
pub fn set_panic_handler<F>(f: F)
where F: Fn(Box<dyn Any + Send + 'static>) + Send + Sync + 'static,
Expand description

Register a custom handler for goroutine panics.

By default, a panicking goroutine prints its payload to stderr and the scheduler continues running other goroutines — the process does not abort.

Calling set_panic_handler replaces the previous handler. The handler receives the Box<dyn Any + Send> payload from std::panic::catch_unwind.

§Example

go_lib::set_panic_handler(|payload| {
    if let Some(s) = payload.downcast_ref::<String>() {
        eprintln!("goroutine panicked: {s}");
    }
});