# Function std::thread::catch_panic [−] [src]

    pub fn catch_panic<F, R>(f: F) -> Result<R> where F: FnOnce() -> R + Send + 'static

Deprecated since 1.6.0

: renamed to std::panic::recover

Invokes a closure, capturing the cause of panic if one occurs.

This function will return `Ok` with the closure's result if the closure does not panic, and will return `Err(cause)` if the closure panics. The `cause` returned is the object with which panic was originally invoked.

It is currently undefined behavior to unwind from Rust code into foreign code, so this function is particularly useful when Rust is called from another language (normally C). This can run arbitrary Rust code, capturing a panic and allowing a graceful handling of the error.

It is not recommended to use this function for a general try/catch mechanism. The `Result` type is more appropriate to use for functions that can fail on a regular basis.

The closure provided is required to adhere to the `'static` bound to ensure that it cannot reference data in the parent stack frame, mitigating problems with exception safety. Furthermore, a `Send` bound is also required, providing the same safety guarantees as `thread::spawn` (ensuring the closure is properly isolated from the parent).

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize`)