@@ -10,22 +10,23 @@ tests. `panic!` is closely tied with the `unwrap` method of both
1010` panic! ` when they are set to [ ` None ` ] or [ ` Err ` ] variants.
1111
1212This macro is used to inject panic into a Rust thread, causing the thread to
13- panic entirely. Each thread's panic can be reaped as the [ ` Box ` ] ` < ` [ ` Any ` ] ` > ` type,
14- and the single-argument form of the ` panic! ` macro will be the value which
15- is transmitted.
13+ panic entirely. This macro panics with a string and uses the [ ` format! ` ] syntax
14+ for building the message.
15+
16+ Each thread's panic can be reaped as the [ ` Box ` ] ` < ` [ ` Any ` ] ` > ` type,
17+ which contains either a ` &str ` or ` String ` for regular ` panic!() ` invocations.
18+ To panic with a value of another other type, [ ` panic_any ` ] can be used.
1619
1720[ ` Result ` ] enum is often a better solution for recovering from errors than
1821using the ` panic! ` macro. This macro should be used to avoid proceeding using
1922incorrect values, such as from external sources. Detailed information about
2023error handling is found in the [ book] .
2124
22- The multi-argument form of this macro panics with a string and has the
23- [ ` format! ` ] syntax for building a string.
24-
2525See also the macro [ ` compile_error! ` ] , for raising errors during compilation.
2626
2727[ ounwrap ] : Option::unwrap
2828[ runwrap ] : Result::unwrap
29+ [ `panic_any` ] : ../std/panic/fn.panic_any.html
2930[ `Box` ] : ../std/boxed/struct.Box.html
3031[ `Any` ] : crate::any::Any
3132[ `format!` ] : ../std/macro.format.html
@@ -42,6 +43,6 @@ program with code `101`.
4243# #![allow(unreachable_code)]
4344panic!();
4445panic!("this is a terrible mistake!");
45- panic!(4); // panic with the value of 4 to be collected elsewhere
4646panic!("this is a {} {message}", "fancy", message = "message");
47+ std::panic::panic_any(4); // panic with the value of 4 to be collected elsewhere
4748```
0 commit comments