From afad5bc8250bbfb0cac2694fbe13fd736190b864 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Sat, 5 Sep 2020 21:49:44 +0200 Subject: [PATCH] Replace panic example with a simpler version --- src/error/panic.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/error/panic.md b/src/error/panic.md index a690642539..5524dbf6f2 100644 --- a/src/error/panic.md +++ b/src/error/panic.md @@ -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"); } ```