Skip to main content

try_catch

Function try_catch 

Source
pub fn try_catch<R, F: FnOnce() -> R + UnwindSafe>(
    func: F,
) -> Result<R, CatchError>
Expand description

PHP proposes a try catch mechanism in C using setjmp and longjmp (bailout) It stores the arg of setjmp into the bailout field of the global executor If a bailout is triggered, the executor will jump to the setjmp and restore the previous setjmp

try_catch allows to use this mechanism

On bailout, this function drops every BailoutGuard that was created inside func, newest first, before it returns. The guards that were created before the call are not changed.

A panic inside func is caught and reported as CatchError::Panic; it is not resumed. Callers that want the panic to propagate call std::panic::resume_unwind with their own payload.

§Returns

  • The result of the function

§Errors