Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update abort_unwind.md #1505

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/error/abort_unwind.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# `abort` and `unwind`

The previous section illustrates the error handling mechanism `panic`. The `cfg_panic` feature makes it possible to execute different code depending on the panic strategy. The current values available are `unwind` and `abort`.
The previous section illustrates the error handling mechanism `panic`. Different code paths can be conditionally compiled based on the panic setting. The current values available are `unwind` and `abort`.


Building on the prior lemonade example, we explicitly use the panic strategy to execise different lines of code.

```rust,editable,ignore,mdbook-runnable
```rust,editable,mdbook-runnable

fn drink(beverage: &str) {
// You shouldn't drink too much sugary beverages.
Expand All @@ -24,7 +24,7 @@ fn main() {

Here is another example focusing on rewriting `drink()` and explicitly use the `unwind` keyword.

```rust,editable,ignore
```rust,editable

#[cfg(panic = "unwind")]
fn ah(){ println!("Spit it out!!!!");}
Expand All @@ -45,7 +45,7 @@ fn main() {

The panic strategy can be set from the command line by using `abort` or `unwind`.

```rust,editable,ignore
rustc lemonade.rc -C panic=abort
```console
rustc lemonade.rs -C panic=abort
```