From ebfe95e632a36e80ef10fdea8cd41295ed51b688 Mon Sep 17 00:00:00 2001 From: Your name Date: Wed, 25 Jan 2023 22:44:05 +0300 Subject: [PATCH 1/2] Add error handling --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9aefb5f..d51f76f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,11 @@ fn main_loop() { stdout().flush().unwrap(); let mut input = String::new(); while stdin().read_line(&mut input).unwrap() != 0 { - println!("{}", evalexpr::eval(&input.trim()).unwrap()); + let result = evalexpr::eval(&input.trim()); + match result { + Ok(succ_res) => println!("{}", succ_res), + Err(_) => println!("Invalid input") + } input.clear(); print!(">>> "); stdout().flush().unwrap(); From 2481dfd3aa8cfab4dd5d7819bc0617f4a515ebf5 Mon Sep 17 00:00:00 2001 From: Ivan Bushchik Date: Wed, 25 Jan 2023 22:49:48 +0300 Subject: [PATCH 2/2] Update error handling for a more beautiful look --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d51f76f..48c03bc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ fn main_loop() { let result = evalexpr::eval(&input.trim()); match result { Ok(succ_res) => println!("{}", succ_res), - Err(_) => println!("Invalid input") + Err(err) => println!("Error: {}", err) } input.clear(); print!(">>> ");