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.

Recoverable errors with Result introduction

Recoverable errors with Result introduction - Rust Tutorial

From the course: First Look: Rust

Start my 1-month free trial

Recoverable errors with Result introduction

- [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…

Contents