Skip to content

Commit

Permalink
fix(errors3): Update hint
Browse files Browse the repository at this point in the history
  • Loading branch information
marisa committed Nov 11, 2019
1 parent d75f5b7 commit feaf6a6
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions exercises/error_handling/errors3.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// errors3.rs
// This is a program that is trying to use a completed version of the
// `total_cost` function from the previous exercise. It's not working though--
// we can't use the `?` operator in the `main()` function! Why not?
// What should we do instead? Scroll for hints!
// `total_cost` function from the previous exercise. It's not working though!
// Why not? What should we do to fix it? Scroll for hints!

use std::num::ParseIntError;

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



// Since the `?` operator returns an `Err` early if the thing it's trying to
// do fails, you can only use the `?` operator in functions that have a
// `Result` as their return type.

// Hence the error that you get if you run this code is:

// ```
// error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
// ```

// So we have to use another way of handling a `Result` within `main`.

// Decide what we should do if `pretend_user_input` has a string value that does
// not parse to an integer, and implement that instead of using the `?`
// operator.
// If other functions can return a `Result`, why shouldn't `main`?

0 comments on commit feaf6a6

Please sign in to comment.