Handling Bad Input
Here's our current code:
main.rs
What's the problem now? Well, right now, if you enter something that is non-numeric, you get an error and it stops the program. Let's handle that!
Just like we are doing when we compare the guess, we can also use match
on the results of parse
, which only has two varients. We use the _
because we don't care what the content of Err
is, we just want to continue.
What if we do want to output the content of Err
? Let's change the code again to print out the message.
Here's what the output looks like now:
Last updated