|
4 | 4 | //! library. Each macro is available for use when linking against the standard
|
5 | 5 | //! library.
|
6 | 6 |
|
7 |
| -/// Panics the current thread. |
8 |
| -/// |
9 |
| -/// This allows a program to terminate immediately and provide feedback |
10 |
| -/// to the caller of the program. `panic!` should be used when a program reaches |
11 |
| -/// an unrecoverable state. |
12 |
| -/// |
13 |
| -/// This macro is the perfect way to assert conditions in example code and in |
14 |
| -/// tests. `panic!` is closely tied with the `unwrap` method of both [`Option`] |
15 |
| -/// and [`Result`][runwrap] enums. Both implementations call `panic!` when they are set |
16 |
| -/// to None or Err variants. |
17 |
| -/// |
18 |
| -/// This macro is used to inject panic into a Rust thread, causing the thread to |
19 |
| -/// panic entirely. Each thread's panic can be reaped as the `Box<Any>` type, |
20 |
| -/// and the single-argument form of the `panic!` macro will be the value which |
21 |
| -/// is transmitted. |
22 |
| -/// |
23 |
| -/// [`Result`] enum is often a better solution for recovering from errors than |
24 |
| -/// using the `panic!` macro. This macro should be used to avoid proceeding using |
25 |
| -/// incorrect values, such as from external sources. Detailed information about |
26 |
| -/// error handling is found in the [book]. |
27 |
| -/// |
28 |
| -/// The multi-argument form of this macro panics with a string and has the |
29 |
| -/// [`format!`] syntax for building a string. |
30 |
| -/// |
31 |
| -/// See also the macro [`compile_error!`], for raising errors during compilation. |
32 |
| -/// |
33 |
| -/// [runwrap]: ../std/result/enum.Result.html#method.unwrap |
34 |
| -/// [`Option`]: ../std/option/enum.Option.html#method.unwrap |
35 |
| -/// [`Result`]: ../std/result/enum.Result.html |
36 |
| -/// [`format!`]: ../std/macro.format.html |
37 |
| -/// [`compile_error!`]: ../std/macro.compile_error.html |
38 |
| -/// [book]: ../book/ch09-00-error-handling.html |
39 |
| -/// |
40 |
| -/// # Current implementation |
41 |
| -/// |
42 |
| -/// If the main thread panics it will terminate all your threads and end your |
43 |
| -/// program with code `101`. |
44 |
| -/// |
45 |
| -/// # Examples |
46 |
| -/// |
47 |
| -/// ```should_panic |
48 |
| -/// # #![allow(unreachable_code)] |
49 |
| -/// panic!(); |
50 |
| -/// panic!("this is a terrible mistake!"); |
51 |
| -/// panic!(4); // panic with the value of 4 to be collected elsewhere |
52 |
| -/// panic!("this is a {} {message}", "fancy", message = "message"); |
53 |
| -/// ``` |
| 7 | +#[doc(include = "../libcore/macros/panic.md")] |
54 | 8 | #[macro_export]
|
55 | 9 | #[stable(feature = "rust1", since = "1.0.0")]
|
56 | 10 | #[allow_internal_unstable(__rust_unstable_column, libstd_sys_internals)]
|
|
0 commit comments