Function extendr_api::thread_safety::catch_r_error

source ·
pub fn catch_r_error<F>(f: F) -> Result<SEXP>
where F: FnOnce() -> SEXP + Copy + UnwindSafe,
Expand description

Wrap an R function such as Rf_findFunction and convert errors and panics into results.

use extendr_api::prelude::*;
test! {
   let res = catch_r_error(|| unsafe {
       throw_r_error("bad things!");
       std::ptr::null_mut()
   });
   assert_eq!(res.is_ok(), false);
}