@@ -10,27 +10,23 @@ Although it is not part of the core language, panics interact with several core
10
10
language features; for instance, out-of-bounds array indexing using the
11
11
` array[index] ` syntax will automatically panic.
12
12
13
- [ macro-panic ] : ../std/macro.panic.html
14
- [ fn-catch-unwind ] : ../std/panic/fn.catch_unwind.html
15
- [ join ] : ../std/thread/struct.JoinHandle.html#method.join
16
-
17
13
## Unwinding
18
14
19
15
Panicking may either be recoverable or non-recoverable, though its behavior
20
16
must be homogenous throughout program execution. A recoverable panic "unwinds"
21
17
Rust frames, just as C++'s ` throw ` unwinds C++ frames. This means that as the
22
- panic traverses Rust frames, live objects in those frames that implement ` Drop `
23
- will have their ` drop ` methods called. Thus, if panic recovery does occur (for
24
- instance at a thread boundary), the objects will have been "cleaned up" just as
25
- if the stack frames had returned normally.
18
+ panic traverses Rust frames, live objects in those frames that [ implement
19
+ ` Drop ` ] [ destructors ] will have their ` drop ` methods called. Thus, if panic
20
+ recovery does occur (for instance at a thread boundary), the objects will have
21
+ been "cleaned up" just as if they had gone out of scope normally.
26
22
27
23
> As long as this guarantee of resource-cleanup is preserved, "unwinding" may
28
24
> be implemented without actually using the mechanism used by C++ for the
29
25
> target platform.
30
26
31
27
> The Standard Library provides two mechanisms for recovering from a panic,
32
28
> [ ` catch_unwind ` ] [ fn-catch-unwind ] (which enables recovery within the
33
- > panicking thread) and [ ` JoinHandle::join ` ] [ join ] (which enables a process to
29
+ > panicking thread) and [ ` JoinHandle::join ` ] [ thread- join] (which enables a process to
34
30
> continue execution without recovering the panicked thread).
35
31
36
32
## Panic runtimes
@@ -46,3 +42,8 @@ runtime_.
46
42
When compiling code that is guaranteed (via a [ compiler option] [ rustc-codegen ] )
47
43
not to unwind, the optimizer may assume that unwinding across Rust frames is
48
44
impossible, which can result in both code-size and runtime speed improvements.
45
+
46
+ [ destructors ] : destructors.md
47
+ [ fn-catch-unwind ] : ../std/panic/fn.catch_unwind.html
48
+ [ macro-panic ] : ../std/macro.panic.html
49
+ [ thread-join ] : ../std/thread/struct.JoinHandle.html#method.join
0 commit comments