|
1 | 1 | # Panic
|
2 | 2 |
|
3 |
| -Rust provides the ability to "panic" upon encountering a runtime error that is |
4 |
| -not part of a function's signature; such an error is typically not expected to |
5 |
| -be recoverable within the context in which the error is encountered. |
| 3 | +Rust provides the ability to "panic" upon encountering an error that is not |
| 4 | +part of a function's signature; such an error is typically not expected to be |
| 5 | +recoverable within the context in which the error is encountered. |
6 | 6 |
|
7 |
| -> **Note**: The Standard Library provides this capability via the [`panic!` macro][macro-panic]. |
| 7 | +Some language constructs, such as out-of-bounds [array indexing], panic |
| 8 | +automatically. There are also language features that provide a level of control |
| 9 | +over panic behavior: |
| 10 | +* A [_panic runtime_](#panic-runtimes) defined how a panic is handled during |
| 11 | + runtime. |
| 12 | +* [FFI ABIs](items/functions.md#unwinding) may alter how panics behave. |
8 | 13 |
|
9 |
| -Although it is not part of the core language, panics interact with several core |
10 |
| -language features; for instance, out-of-bounds array indexing using the |
11 |
| -`array[index]` syntax will automatically panic. |
| 14 | +> **Note**: The Standard Library provides the capability to explicitly panic |
| 15 | +> via the [`panic!` macro][macro-panic]. |
12 | 16 |
|
13 | 17 | ## Unwinding
|
14 | 18 |
|
15 | 19 | Panicking may either be recoverable or non-recoverable, though its behavior
|
16 |
| -must be homogenous throughout program execution. A recoverable panic "unwinds" |
| 20 | +must be uniform throughout program execution. A recoverable panic "unwinds" |
17 | 21 | Rust frames, just as C++'s `throw` unwinds C++ frames. This means that as the
|
18 | 22 | panic traverses Rust frames, live objects in those frames that [implement
|
19 | 23 | `Drop`][destructors] will have their `drop` methods called. Thus, if panic
|
@@ -46,6 +50,7 @@ impossible, which can result in both code-size and runtime speed improvements.
|
46 | 50 |
|
47 | 51 | See also ["The Rust runtime"][runtime].
|
48 | 52 |
|
| 53 | +[array-indexing]: expressions/array-expr.md#array-and-slice-indexing-expressions |
49 | 54 | [destructors]: destructors.md
|
50 | 55 | [fn-catch-unwind]: ../std/panic/fn.catch_unwind.html
|
51 | 56 | [macro-panic]: ../std/macro.panic.html
|
|
0 commit comments