File tree 1 file changed +9
-9
lines changed
1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 1
1
# ` panic `
2
2
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:
6
6
7
7
``` 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!!!!"); }
11
11
12
- println!("I love {}s!!!!! ", gift );
12
+ println!("Some refreshing {} is all I need. ", beverage );
13
13
}
14
14
15
15
fn main() {
16
- give_princess("teddy bear ");
17
- give_princess("snake ");
16
+ drink("water ");
17
+ drink("lemonade ");
18
18
}
19
19
```
You can’t perform that action at this time.
0 commit comments