Skip to content

Commit bfda4ca

Browse files
authored
Updated TODO errors3.rs
1 parent 26cf498 commit bfda4ca

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

exercises/13_error_handling/errors3.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ fn main() {
2020
let pretend_user_input = "8";
2121

2222
// Don't change this line.
23-
let cost = total_cost(pretend_user_input)?;
23+
let cost = total_cost(pretend_user_input);
2424

25-
if cost > tokens {
26-
println!("You can't afford that many!");
27-
} else {
28-
tokens -= cost;
29-
println!("You now have {tokens} tokens.");
25+
match cost {
26+
Ok(cost) => {
27+
if cost > tokens {
28+
println!("You can't afford that many!");
29+
} else {
30+
tokens -= cost;
31+
println!("You now have {tokens} tokens.");
32+
}
33+
},
34+
Err(error) => {
35+
println!("Error calculating the total cost: {}", error)
36+
}
3037
}
3138
}

0 commit comments

Comments
 (0)