Add error handling

This commit is contained in:
Your name 2023-01-25 22:44:05 +03:00
parent 27a825b2a2
commit ebfe95e632

View file

@ -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();