From the course: Rust Essential Training
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Challenge: Handle errors - Rust Tutorial
From the course: Rust Essential Training
Challenge: Handle errors
- [Narrator] It's time for another challenge. To practice handling errors. Your goal this time will be to enhance your solution to the previous higher or lower guessing game challenge. You incorporate error handling. If the user enters invalid input rather than panicking and terminating the program, it should print a message letting the user know there was a problem. And then prompt them to enter another guess. Keep in mind, if you have an uncooperative user they may try multiple invalid inputs. So your program should be able to handle that situation. You can use your own solution to the previous challenge as a starting point. Or my solution which I've included in the exercise files. Notice that the read line method on line 11 and the parse method on line 12, both have the potential to fail. And therefore, return a result enum. This code is currently using the expect method. To get the value from those result enums.…
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.