pub fn update_hook<F>(hook_fn: F) where
    F: Fn(&(dyn Fn(&PanicInfo<'_>) + Send + Sync + 'static), &PanicInfo<'_>) + Sync + Send + 'static, 
🔬This is a nightly-only experimental API. (panic_update_hook #92649)
Expand description

Atomic combination of take_hook and set_hook. Use this to replace the panic handler with a new panic handler that does something and then executes the old handler.

Panics

Panics if called from a panicking thread.

Examples

The following will print the custom message, and then the normal output of panic.

#![feature(panic_update_hook)]
use std::panic;

// Equivalent to
// let prev = panic::take_hook();
// panic::set_hook(move |info| {
//     println!("...");
//     prev(info);
// );
panic::update_hook(move |prev, info| {
    println!("Print custom message and execute panic handler as usual");
    prev(info);
});

panic!("Custom and then normal");
Run