File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 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
1515fn main() {
16- give_princess("teddy bear ");
17- give_princess("snake ");
16+ drink("water ");
17+ drink("lemonade ");
1818}
1919```
You can’t perform that action at this time.
0 commit comments