Function try_catch

Source
pub unsafe extern "C-unwind" fn try_catch(
    f: extern "C-unwind" fn(*mut c_void),
    context: *mut c_void,
    error: *mut *mut c_void,
) -> u8
Expand description

Call the given function inside an Objective-C @try/@catch block.

Defined in src/try_catch.m and compiled in build.rs.

Alternatively, we could manually write assembly for this function like objrs does does, that would cut down on a build stage (and would probably give us a bit better performance), but it gets unwieldy very quickly, so I chose the much more stable option.

Another thing to remember: While Rust’s and Objective-C’s unwinding mechanisms are similar now, Rust’s is explicitly unspecified, and they may diverge significantly in the future; so handling this in pure Rust (using mechanisms like core::intrinsics::r#try) is not an option!

§Panics

This panics / continues unwinding if the unwind is not triggered by an Objective-C exception (i.e. it was triggered by Rust/C++/…).