Skip to main content

drop_panic_payload

Function drop_panic_payload 

Source
pub fn drop_panic_payload(payload: Box<dyn Any + Send>)
Expand description

Drops a caught panic payload, containing any panic its Drop raises.

If dropping the payload panics, that second panic’s payload is dropped the same way, and so on — a payload whose Drop panics usually panics with an ordinary message, whose own drop cannot panic, so the chain ends at once and nothing is leaked. Only after MAX_NESTED_PAYLOAD_DROPS consecutive panicking drops is the remaining payload leaked with std::mem::forget: the chain is user code with no inherent bound, and leaking one allocation is the price of never aborting.

§Example

struct Bomb;
impl Drop for Bomb {
    fn drop(&mut self) {
        panic!("payload destructor exploded");
    }
}

let payload = std::panic::catch_unwind(|| std::panic::panic_any(Bomb)).unwrap_err();
// Dropping `payload` directly would unwind out of here.
quack_rs::callback::drop_panic_payload(payload);