Skip to content

Commit f4950c6

Browse files
authored
Merge pull request #1380 from badboy/simpler-panic-example
Replace panic example with a simpler version
2 parents 541be6f + afad5bc commit f4950c6

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
```

0 commit comments

Comments
 (0)