For recoverable errors, the Result enum can be used to appropriately identify the error type and handle it as need be.
- [Instructor] Recoverable errors are situations in which…it's reasonable to report a problem to the user,…and retry the operation.…Most errors aren't serious enough…to require the program to stop entirely.…Sometimes when a function fails,…it's for a reason that we can easily interpret…and respond to.…For example, if you try to open a file…and that operation fails because the file doesn't exist,…we might want to create the file,…instead of terminating the process.…
We can achieve this by using the result enum.…Result enum is defined as having two radiants:…Ok and Err, which denotes error.…The T and E are generic type parameters.…T represents the type of the value…that'll be returned in a success case…within the Ok variant,…and E represents the type of the error…that will returned in a failure case…within the Err variant.…
Let's create a new project for this…and call it "results."…Let's navigate into the project.…Let's jump to code.…So results is created here for us, src and then main.rs.…Let's now attempt to read a file that does not exist.…
- Installing Rust
- Data types
- Adjusting memory allocation
- Setting up race conditions
- Working with functions
- Exploring references and borrowing
- Using structs
- Method syntax
- Demonstrating recoverable errors with Result
- Working with enums
- Getting user input
Skill Level Beginner
1. Hello, Rust!
2. Basic Programming Concepts
3. Ownership in Rust
4. Data Handling and Pattern Matching in Rust
5. Error Handling
6. Sample Rust Project: The Guessing Game
Next steps1m 14s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.