Skip to main content

catch_unwind

Function catch_unwind 

Source
pub unsafe fn catch_unwind<Data>(
    _try_fn: unsafe fn(*mut Data),
    _data: *mut Data,
    _catch_fn: unsafe fn(*mut Data, *mut u8),
) -> bool
where Data: Thin,
🔬This is a nightly-only experimental API. (core_intrinsics)
Expand description

Rust’s “try catch” construct for unwinding. Invokes the function pointer try_fn with the data pointer data, and calls catch_fn if unwinding occurs while try_fn runs. Returns true if unwinding occurred and catch_fn was called; returns false otherwise.

catch_fn must not unwind.

The third argument is a function called if an unwind occurs (both Rust panic and foreign unwinds). This function takes the data pointer and a pointer to the target- and runtime-specific exception object that was caught.

Note that in the case of a foreign unwinding operation, the exception object data may not be safely usable from Rust, and should not be directly exposed via the standard library. To prevent unsafe access, the library implementation may either abort the process or present an opaque error type to the user.

For more information, see the compiler’s source, as well as the documentation for the stable version of this intrinsic, std::panic::catch_unwind.