From the course: First Look: Rust
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Unrecoverable errors with panic! - Rust Tutorial
From the course: First Look: Rust
Unrecoverable errors with panic!
- [Instructor] Rust's commitment to reliability extends to error handling. Errors are a fact of life in software, so Rust has a number of features for handling situations in which something goes wrong. Rust groups errors into two major categories: Recoverable and unrecoverable errors. Recoverable errors are situations in which it's reasonable to report the problem to the user, and retry the operation, like a file not found error. Unrecoverable errors are always symptoms of bugs, like trying to access a location beyond the end of an area. Rust has to type result for recoverable errors, and panic! macro for unrecoverable errors, that stops execution when it encounters unrecoverable errors. Sometimes, bad things happen in your code, and there's nothing you can do about it. In these cases, Rust has the panic! macro. When the panic! macro executes, your program will print a failure message, unwind, and clean up the stack, and then quit. The most common situation this occurs in is when a…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.