Function std::rt::unwind::try
[−]
[src]
pub unsafe fn try<F: FnOnce()>(f: F) -> Result<(), Box<Any + Send>>
Invoke a closure, capturing the cause of panic if one occurs.
This function will return Ok(())
`Ok(())if the closure did not panic, and will return
` if the closure did not panic, and will
return Err(cause)
`Err(cause)if the closure panics. The
` if the closure panics. The cause
`cause` returned is the
object with which panic was originally invoked.
This function also is unsafe for a variety of reasons:
This is not safe to call in a nested fashion. The unwinding interface for Rust is designed to have at most one try/catch block per thread, not multiple. No runtime checking is currently performed to uphold this invariant, so this function is not safe. A nested try/catch block may result in corruption of the outer try/catch block's state, especially if this is used within a thread itself.
It is not sound to trigger unwinding while already unwinding. Rust threads have runtime checks in place to ensure this invariant, but it is not guaranteed that a rust thread is in place when invoking this function. Unwinding twice can lead to resource leaks where some destructors are not run.