Module std::panic

Recovering from a panic: catch_panic runs a function and turns a panic inside it into an Err carrying the panic's message, after unwinding (destructors and guards run). Without it the root's Panic handler is terminal and a panic ends the program.

Source: std/panic.weir; committed interface: std/panic.iface. Index

fn catch_panic

pub fn catch_panic<T: linear>(f: fn() -> T with Panic) -> Result<T, Str>

Runs f, answering Ok with its result, or Err(message) if it panics.

f's with Panic is served here, so the panic stops at this call: the unwind runs every destructor and guard between the panic and here, and the caller needs no guard of its own.

Committed interface (std/panic.iface):

holds what may not move at a scheduling point: always
callback f: envelope {A, S}