|
1 | 1 | # The Rust runtime |
2 | 2 |
|
3 | | -This section documents features that define some aspects of the Rust runtime. A list of such |
4 | | -features is shown below: |
| 3 | +This section documents features that define some aspects of the Rust runtime. |
5 | 4 |
|
6 | | -- `#[panic_handler]`, the panicking behavior |
| 5 | +## The `panic_handler` attribute |
7 | 6 |
|
8 | | -## `#[panic_handler]` |
9 | | - |
10 | | -The `panic_handler` attribute can only be applied to a function with signature |
11 | | -`fn(&PanicInfo) -> !`. The function marked with this attribute defines the behavior of panics. The |
| 7 | +The *`panic_handler` attribute* can only be applied to a function with signature |
| 8 | +`fn(&PanicInfo) -> !`. The function marked with this [attribute] defines the behavior of panics. The |
12 | 9 | [`PanicInfo`] struct contains information about the location of the panic. There must be a single |
13 | 10 | `panic_handler` function in the dependency graph of a binary, dylib or cdylib crate. |
14 | 11 |
|
15 | | -[`PanicInfo`]: https://doc.rust-lang.org/nightly/core/panic/struct.PanicInfo.html |
16 | | - |
17 | 12 | Below is shown a `panic_handler` function that logs the panic message and then halts the |
18 | 13 | thread. |
19 | 14 |
|
@@ -51,7 +46,12 @@ fn panic(info: &PanicInfo) -> ! { |
51 | 46 |
|
52 | 47 | ### Standard behavior |
53 | 48 |
|
54 | | -The standard library provides an implementation of `panic_handler` than defaults |
55 | | -to unwinding the stack but that can be [changed to abort the process][abort]. |
| 49 | +The standard library provides an implementation of `panic_handler` that |
| 50 | +defaults to unwinding the stack but that can be [changed to abort the |
| 51 | +process][abort]. The standard library's panic behavior can be modified at |
| 52 | +runtime with the [set_hook] function. |
56 | 53 |
|
57 | | -[abort]: ../book/2018-edition/ch09-01-unrecoverable-errors-with-panic.html |
| 54 | +[`PanicInfo`]: ../core/panic/struct.PanicInfo.html |
| 55 | +[abort]: ../book/ch09-01-unrecoverable-errors-with-panic.html |
| 56 | +[attribute]: attributes.html |
| 57 | +[set_hook]: ../std/panic/fn.set_hook.html |
0 commit comments