Skip to content

Commit

Permalink
clarify recoverable vs non-recoverable panics
Browse files Browse the repository at this point in the history
  • Loading branch information
BatmanAoD committed Aug 25, 2024
1 parent 1effd8b commit af09649
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/panic.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ over panic behavior:
## Unwinding

Panicking may either be recoverable or non-recoverable, though its behavior
must be uniform throughout program execution. A recoverable panic "unwinds"
Rust frames, just as C++'s `throw` unwinds C++ frames. This means that as the
panic traverses Rust frames, live objects in those frames that [implement
`Drop`][destructors] will have their `drop` methods called. Thus, if panic
recovery does occur (for instance at a thread boundary), the objects will have
been "cleaned up" just as if they had gone out of scope normally.
Panicking may either be recoverable or non-recoverable, though it can be
configured (via `panic=abort`) to always be non-recoverable. (The converse is
not true: `panic=unwind` does not guarantee that all panics are recoverable,
only that panicking via the `panic!` macro and similar standard library
mechanisms is recoverable.) A recoverable panic "unwinds" Rust frames, just as
C++'s `throw` unwinds C++ frames. This means that as the panic traverses Rust
frames, live objects in those frames that [implement `Drop`][destructors] will
have their `drop` methods called. Thus, if panic recovery does occur (for
instance at a thread boundary), the objects will have been "cleaned up" just as
if they had gone out of scope normally.

> **Note**: As long as this guarantee of resource-cleanup is preserved,
> "unwinding" may be implemented without actually using the mechanism used by
Expand Down

0 comments on commit af09649

Please sign in to comment.