Skip to main content

catch_panic

Function catch_panic 

Source
pub fn catch_panic<T, F>(f: F) -> Result<T, Box<dyn Any + Send + 'static>>
where F: FnOnce() -> T + UnwindSafe,
Expand description

Executes a closure and catches any panics that occur, returning a Result.

ยงExample

use reratui_panic::catch_panic;

let ok = catch_panic(|| 42);
assert!(ok.is_ok());
assert_eq!(ok.unwrap(), 42);

let err = catch_panic(|| panic!("fail!"));
assert!(err.is_err());