pub fn catch<F, R>(block: F) -> Result<R, ExtExceptionInfo>where
F: FnOnce() -> R + UnwindSafe,
Expand description
Catches an exception raised by throw
.
Runs block
. If an exception is thrown during its execution, returns boxed
exception details. Otherwise, returns the return value of the block.
Internally, this function sets up a setjmp
buffer, and throw
performs
a longjmp
back to it. No unwinding occurs: drop methods for any objects
created in the dynamic scope of the callback will not run. So, be wary of
resource leaks.
Despite this function’s similar type signature to
std::panic::catch_unwind
, exceptions and panics are distinct. This
function will not catch panics and catch_unwind
will not catch exceptions.
If block
panics, the panic will continue to propagate out from this call.
This function will not catch anything that was not thrown by throw
, so a
signal being raised during the execution of block
will not automatically
result in it being caught. You first need to use register_hook
to
register a hook which calls throw
.