# 1.0.0[−][src]Macro std::panic

    macro_rules! panic {
        () => { ... };
        ($msg:expr) => { ... };
        ($msg:expr,) => { ... };
        ($fmt:expr, $($arg:tt)+) => { ... };
    }

The entry point for panic of Rust threads.

This allows a program to terminate immediately and provide feedback to the caller of the program. `panic!` should be used when a program reaches an unrecoverable problem.

This macro is the perfect way to assert conditions in example code and in tests. `panic!` is closely tied with the `unwrap` method of both `Option` and `Result` enums. Both implementations call `panic!` when they are set to None or Err variants.

This macro is used to inject panic into a Rust thread, causing the thread to panic entirely. Each thread's panic can be reaped as the `Box<Any>` type, and the single-argument form of the `panic!` macro will be the value which is transmitted.

`Result` enum is often a better solution for recovering from errors than using the `panic!` macro. This macro should be used to avoid proceeding using incorrect values, such as from external sources. Detailed information about error handling is found in the book.

The multi-argument form of this macro panics with a string and has the `format!` syntax for building a string.

See also the macro `compile_error!`, for raising errors during compilation.

# Current implementation

If the main thread panics it will terminate all your threads and end your program with code `101`.

# Examples

    panic!();
    panic!("this is a terrible mistake!");
    panic!(4); // panic with the value of 4 to be collected elsewhere
    panic!("this is a {} {message}", "fancy", message = "message");Run

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## 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` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)