Skip to content

Commit 2cc5d72

Browse files
authored
Rollup merge of #83254 - jfrimmel:panic_output-stream, r=m-ou-se,joshtriplett
Include output stream in `panic!()` documentation Fixes #83252.
2 parents 1a0e32f + 19bd066 commit 2cc5d72

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

library/core/src/macros/panic.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ tests. `panic!` is closely tied with the `unwrap` method of both
99
[`Option`][ounwrap] and [`Result`][runwrap] enums. Both implementations call
1010
`panic!` when they are set to [`None`] or [`Err`] variants.
1111

12-
This macro is used to inject panic into a Rust thread, causing the thread to
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,
12+
When using `panic!()` you can specify a string payload, that is built using
13+
the [`format!`] syntax. That payload is used when injecting the panic into
14+
the calling Rust thread, causing the thread to panic entirely.
15+
16+
The behavior of the default `std` hook, i.e. the code that runs directly
17+
after the panic is invoked, is to print the message payload to
18+
`stderr` along with the file/line/column information of the `panic!()`
19+
call. You can override the panic hook using [`std::panic::set_hook()`].
20+
Inside the hook a panic can be accessed as a `&dyn Any + Send`,
1721
which contains either a `&str` or `String` for regular `panic!()` invocations.
1822
To panic with a value of another other type, [`panic_any`] can be used.
1923

@@ -26,6 +30,7 @@ See also the macro [`compile_error!`], for raising errors during compilation.
2630

2731
[ounwrap]: Option::unwrap
2832
[runwrap]: Result::unwrap
33+
[`std::panic::set_hook()`]: ../std/panic/fn.set_hook.html
2934
[`panic_any`]: ../std/panic/fn.panic_any.html
3035
[`Box`]: ../std/boxed/struct.Box.html
3136
[`Any`]: crate::any::Any

0 commit comments

Comments
 (0)