From d2ec831ecde3510f0f406ac26cf8d2991cbb79b8 Mon Sep 17 00:00:00 2001 From: Nathan Stocks Date: Wed, 1 Dec 2021 09:51:23 -0700 Subject: [PATCH] explain the errors challenge more thoroughly to avoid student confusion --- exercise/errors/src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/exercise/errors/src/main.rs b/exercise/errors/src/main.rs index b19b43e..eddd3ab 100644 --- a/exercise/errors/src/main.rs +++ b/exercise/errors/src/main.rs @@ -49,8 +49,12 @@ fn main() { ]; for dolphin in &dolphins { // Challenge: Change main() so that it returns a Result, and instead of handling the error - // that play_time returns, use the try operator to only handle the success condition. How - // does the output of the program change? + // that play_time returns, use the try (?) operator to only handle the success condition. + // + // If done correctly, the output of the program will become much shorter. Since play_time + // returns an Err variant the first time it is called, the try operator will return it from + // main(), which will end the program at the first error. anyhow's Result will take care of + // formatting the error output for us. match play_time(dolphin) { Ok(responses) => { println!("{} did a FABULOUS PERFORMANCE!", dolphin.name);