[][src]Attribute Macro alass_ffi_macros::catch_panic

#[catch_panic]

Wraps a function body with std::panic::catch_unwind to ensure that panics won't unwind accross the ffi boundary. The macro argument should be the return value of the function in case of panic, or no argument if it returns void.

Also logs error! message upon panic so log crate must be in scope.

Example function with no return value:

 
    #[catch_panic]
    pub extern "C" fn foo() {
        // may panic here...
    }

Example function that returns 0 on success and -1 on panic:

 
    #[catch_panic(-1)]
    pub extern "C" fn bar() -> c_int {
        // may panic here...
        0
    }