Skip to content

Commit dcfb427

Browse files
author
marisa
committed
fix(errors3): Update hint
Closes #185.
1 parent ad03d18 commit dcfb427

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

exercises/error_handling/errors3.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// errors3.rs
22
// This is a program that is trying to use a completed version of the
3-
// `total_cost` function from the previous exercise. It's not working though--
4-
// we can't use the `?` operator in the `main()` function! Why not?
5-
// What should we do instead? Scroll for hints!
3+
// `total_cost` function from the previous exercise. It's not working though!
4+
// Why not? What should we do to fix it? Scroll for hints!
65

76
use std::num::ParseIntError;
87

@@ -45,18 +44,4 @@ pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
4544

4645

4746

48-
// Since the `?` operator returns an `Err` early if the thing it's trying to
49-
// do fails, you can only use the `?` operator in functions that have a
50-
// `Result` as their return type.
51-
52-
// Hence the error that you get if you run this code is:
53-
54-
// ```
55-
// error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
56-
// ```
57-
58-
// So we have to use another way of handling a `Result` within `main`.
59-
60-
// Decide what we should do if `pretend_user_input` has a string value that does
61-
// not parse to an integer, and implement that instead of using the `?`
62-
// operator.
47+
// If other functions can return a `Result`, why shouldn't `main`?

0 commit comments

Comments
 (0)