@@ -10,22 +10,23 @@ tests. `panic!` is closely tied with the `unwrap` method of both
10
10
` panic! ` when they are set to [ ` None ` ] or [ ` Err ` ] variants.
11
11
12
12
This 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.
16
19
17
20
[ ` Result ` ] enum is often a better solution for recovering from errors than
18
21
using the ` panic! ` macro. This macro should be used to avoid proceeding using
19
22
incorrect values, such as from external sources. Detailed information about
20
23
error handling is found in the [ book] .
21
24
22
- The multi-argument form of this macro panics with a string and has the
23
- [ ` format! ` ] syntax for building a string.
24
-
25
25
See also the macro [ ` compile_error! ` ] , for raising errors during compilation.
26
26
27
27
[ ounwrap ] : Option::unwrap
28
28
[ runwrap ] : Result::unwrap
29
+ [ `panic_any` ] : ../std/panic/fn.panic_any.html
29
30
[ `Box` ] : ../std/boxed/struct.Box.html
30
31
[ `Any` ] : crate::any::Any
31
32
[ `format!` ] : ../std/macro.format.html
@@ -42,6 +43,6 @@ program with code `101`.
42
43
# #![allow(unreachable_code)]
43
44
panic!();
44
45
panic!("this is a terrible mistake!");
45
- panic!(4); // panic with the value of 4 to be collected elsewhere
46
46
panic!("this is a {} {message}", "fancy", message = "message");
47
+ std::panic::panic_any(4); // panic with the value of 4 to be collected elsewhere
47
48
```
0 commit comments