]> git.proxmox.com Git - rustc.git/blob - src/doc/rust-by-example/src/error/panic.md
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / doc / rust-by-example / src / error / panic.md
1 # `panic`
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:
6
7 ```rust,editable,ignore,mdbook-runnable
8 fn drink(beverage: &str) {
9 // You shouldn't drink too much sugary beverages.
10 if beverage == "lemonade" { panic!("AAAaaaaa!!!!"); }
11
12 println!("Some refreshing {} is all I need.", beverage);
13 }
14
15 fn main() {
16 drink("water");
17 drink("lemonade");
18 }
19 ```