Skip to content

Commit

Permalink
Merge pull request #1380 from badboy/simpler-panic-example
Browse files Browse the repository at this point in the history
Replace panic example with a simpler version
  • Loading branch information
marioidival authored Sep 28, 2020
2 parents 541be6f + afad5bc commit f4950c6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/error/panic.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# `panic`

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

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

0 comments on commit f4950c6

Please sign in to comment.