diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-03-19 23:01:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-19 23:01:38 +0100 |
| commit | 2cc5d727926dd8868ef0f7f62748da9105704402 (patch) | |
| tree | 76e6f4de5ab0c78fe1bd58f2ca3bbf9fd336fe89 | |
| parent | 1a0e32f4bc30318f4e15d200039bdbc2ea659fdb (diff) | |
| parent | 19bd0669b45fcc5ce81b8003cafccf318c3cc22e (diff) | |
Rollup merge of #83254 - jfrimmel:panic_output-stream, r=m-ou-se,joshtriplett
Include output stream in `panic!()` documentation Fixes #83252.
| -rw-r--r-- | library/core/src/macros/panic.md | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/library/core/src/macros/panic.md b/library/core/src/macros/panic.md index 6e502426df9..5127a16bbfd 100644 --- a/library/core/src/macros/panic.md +++ b/library/core/src/macros/panic.md @@ -9,11 +9,15 @@ tests. `panic!` is closely tied with the `unwrap` method of both [`Option`][ounwrap] and [`Result`][runwrap] 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. This macro panics with a string and uses the [`format!`] syntax -for building the message. - -Each thread's panic can be reaped as the [`Box`]`<`[`Any`]`>` type, +When using `panic!()` you can specify a string payload, that is built using +the [`format!`] syntax. That payload is used when injecting the panic into +the calling Rust thread, causing the thread to panic entirely. + +The behavior of the default `std` hook, i.e. the code that runs directly +after the panic is invoked, is to print the message payload to +`stderr` along with the file/line/column information of the `panic!()` +call. You can override the panic hook using [`std::panic::set_hook()`]. +Inside the hook a panic can be accessed as a `&dyn Any + Send`, which contains either a `&str` or `String` for regular `panic!()` invocations. To panic with a value of another other type, [`panic_any`] can be used. @@ -26,6 +30,7 @@ See also the macro [`compile_error!`], for raising errors during compilation. [ounwrap]: Option::unwrap [runwrap]: Result::unwrap +[`std::panic::set_hook()`]: ../std/panic/fn.set_hook.html [`panic_any`]: ../std/panic/fn.panic_any.html [`Box`]: ../std/boxed/struct.Box.html [`Any`]: crate::any::Any |
