abort_on_panic 1.0.0

Intercept panic! from unsafe locations and abort the process

Crate abort_on_panic [] [src]

When calling Rust code from C, it's unsafe to call panic!. Doing so may cause unsafe behavior. But when calling user-defined functions, we sometimes need to enforce these rules.

#[macro_use]
extern crate abort_on_panic;
 
#[test]
pub fn test_macro() {
    let result = abort_on_panic!({ "value" });
    assert_eq!("value", result);
 
    abort_on_panic!("cannot panic inside FFI callbacks", {
        // ...
    });
}

Macros

abort_on_panic!

Run a block of code, aborting the entire process if it tries to panic.

Structs

PanicGuard

Once this object is created, it can only be destroyed in an orderly fashion. Attempting to clean it up from a panic handler will abort the process.