Skip to content

Commit afad5bc

Browse files
committedSep 5, 2020
Replace panic example with a simpler version
1 parent 19f0a03 commit afad5bc

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed
 

‎src/error/panic.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# `panic`
22

3-
The simplest error handling mechanism we will see is `panic`. It prints an
4-
error message, starts unwinding the stack, and usually exits the program.
5-
Here, we explicitly call `panic` on our error condition:
3+
The simplest error handling mechanism we will see is `panic`. It prints an
4+
error message, starts unwinding the stack, and usually exits the program.
5+
Here, we explicitly call `panic` on our error condition:
66

77
```rust,editable,ignore,mdbook-runnable
8-
fn give_princess(gift: &str) {
9-
// Princesses hate snakes, so we need to stop if she disapproves!
10-
if gift == "snake" { panic!("AAAaaaaa!!!!"); }
8+
fn drink(beverage: &str) {
9+
// You shouldn't drink too much sugary beverages.
10+
if beverage == "lemonade" { panic!("AAAaaaaa!!!!"); }
1111
12-
println!("I love {}s!!!!!", gift);
12+
println!("Some refreshing {} is all I need.", beverage);
1313
}
1414
1515
fn main() {
16-
give_princess("teddy bear");
17-
give_princess("snake");
16+
drink("water");
17+
drink("lemonade");
1818
}
1919
```

3 commit comments

Comments
 (3)

dariuswiles commented on Mar 5, 2021

@dariuswiles
Contributor

This change creates an inconsistency with the next page in the book, option_unwrap.md, which refers back to this example and builds upon it. The two pages need to be made consistent, e.g., by updating the option_unwrap.md page.

badboy commented on Mar 5, 2021

@badboy
MemberAuthor

This change creates an inconsistency with the next page in the book, option_unwrap.md, which refers back to this example and builds upon it. The two pages need to be made consistent, e.g., by updating the option_unwrap.md page.

Oh, when I did that I didn't check that. Would you be able to open that as a bug? Easier to track that way. I might find some time tomorrow to adjust the other example.

dariuswiles commented on Mar 5, 2021

@dariuswiles
Contributor

This change creates an inconsistency with the next page in the book, option_unwrap.md, which refers back to this example and builds upon it. The two pages need to be made consistent, e.g., by updating the option_unwrap.md page.

Oh, when I did that I didn't check that. Would you be able to open that as a bug? Easier to track that way. I might find some time tomorrow to adjust the other example.

Sure. I opened issue #1424.

Please sign in to comment.