Function objc2::exception::catch[][src]

pub unsafe fn catch<R>(
    closure: impl FnOnce() -> R
) -> Result<R, Option<Id<Object, Shared>>>
Expand description

Tries to execute the given closure and catches an Objective-C exception if one is thrown.

Returns a Result that is either Ok if the closure succeeded without an exception being thrown, or an Err with a pointer to an exception if one was thrown. The exception is retained and so must be released.

Safety

The given closure must not panic (e.g. normal Rust unwinding into this causes undefined behaviour).

Additionally, this unwinds through the closure from Objective-C, which is undefined behaviour until C-unwind is stabilized, see RFC-2945.