Function panic_control::spawn_quiet [] [src]

pub fn spawn_quiet<T, F>(f: F) -> JoinHandle<T> where
    F: FnOnce() -> T,
    F: Send + 'static,
    T: Send + 'static, 

Like std::thread::spawn(), but disables the panic hook if the spawned thread panics.

The process-global panic hook, either installed with std::panic::set_hook() or the standard library default, gets augmented with a filter that disables invocation of the hook closure if the spawned thread panics.

This function can be used in any order together with other functions and methods of this crate that modify the panic hook.

Caveats

Note that the suppression can apply to the default panic hook that is normally used to report assertion failures and other unexpected panics on the standard error stream. The only remaining way to observe the panic is by checking the result of join() for the spawned thread.

Other code within the program that modifies the panic hook, concurrently to, or after, a call to this function, may cause the suppression not to work as intended. See the documentation on the function disable_hook_in_current_thread() for possible pitfalls.

Examples

use panic_control::spawn_quiet;

let h = spawn_quiet(|| {
    assert!(false, "I'm panicking, \
        but you can only learn about it through join()");
});
let res = h.join();
assert!(res.is_err());