From bd20d7b591f9bfedf01403550c74a32268dc9984 Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Thu, 28 Mar 2019 22:37:26 +0530 Subject: handler passes errors up the call stack --- src/error/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/error/mod.rs b/src/error/mod.rs index 14153fe..a269555 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -11,19 +11,19 @@ pub enum Math { OutOfBounds, } -pub fn handler(e: CalcError) { +pub fn handler(e: CalcError) -> String { match e { CalcError::Math(math_err) => { match math_err { - Math::DivideByZero => println!("Math Error: Divide by zero error!"), - Math::OutOfBounds => println!("Domain Error: Out of bounds!") + Math::DivideByZero => format!("Math Error: Divide by zero error!"), + Math::OutOfBounds => format!("Domain Error: Out of bounds!") } }, CalcError::Syntax(details) => { - println!("Syntax Error: {}", details); + format!("Syntax Error: {}", details) }, CalcError::Parser(details) => { - println!("Parser Error: {}", details); + format!("Parser Error: {}", details) } } } -- cgit v1.2.3