From 9eb1539c078c4814124aab986899b0b870fb6050 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Mon, 24 Aug 2020 14:27:48 -0400 Subject: [PATCH] Added some exception handling --- CSClasses/Algorithms.cs | 12 ++++++------ CSClasses/Exceptions/InvalidResult.cs | 13 +++++++++++++ CSClasses/Stopwatch.cs | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 CSClasses/Exceptions/InvalidResult.cs diff --git a/CSClasses/Algorithms.cs b/CSClasses/Algorithms.cs index c7f42ad..592bf72 100644 --- a/CSClasses/Algorithms.cs +++ b/CSClasses/Algorithms.cs @@ -123,9 +123,9 @@ namespace mee{ goalNumber /= goalNumber; } - //TODO: If for some reason the goalNumber is not 1 throw an error + //If for some reason the goalNumber is not 1 throw an exception if(goalNumber != 1){ - + throw new mee.Exceptions.InvalidResult("Factor did not end as 1"); } //Return the list of factors @@ -157,9 +157,9 @@ namespace mee{ goalNumber /= goalNumber; } - //TODO: If for some reason the goalNumber is not 1 throw an error + //If for some reason the goalNumber is not 1 throw an exception if(goalNumber != 1){ - + throw new mee.Exceptions.InvalidResult("Factor did not end as 1"); } //Return the list of factors @@ -191,9 +191,9 @@ namespace mee{ goalNumber /= goalNumber; } - //TODO: If for some reason the goalNumber is not 1 throw an error + //If for some reason the goalNumber is not 1 throw an exception if(goalNumber != 1){ - + throw new mee.Exceptions.InvalidResult("Factor did not end as 1"); } //Return the list of factors diff --git a/CSClasses/Exceptions/InvalidResult.cs b/CSClasses/Exceptions/InvalidResult.cs new file mode 100644 index 0000000..ba7a42c --- /dev/null +++ b/CSClasses/Exceptions/InvalidResult.cs @@ -0,0 +1,13 @@ +namespace mee.Exceptions{ + [System.Serializable] + public class InvalidResult : System.Exception{ + public InvalidResult(){ + } + public InvalidResult(string message) : base(message){ + } + public InvalidResult(string message, System.Exception inner) : base(message, inner){ + } + protected InvalidResult(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) : base(info, context){ + } + } +} diff --git a/CSClasses/Stopwatch.cs b/CSClasses/Stopwatch.cs index e3a09c0..ad31920 100644 --- a/CSClasses/Stopwatch.cs +++ b/CSClasses/Stopwatch.cs @@ -106,7 +106,7 @@ namespace mee{ case TIME_RESOLUTION.MINUTE: time += " minutes"; break; case TIME_RESOLUTION.HOUR: time += " hours"; break; case TIME_RESOLUTION.ERROR: - default: time = "There was an error computing the time"; break; //TODO: This should throw an exception instead + default: throw new mee.Exceptions.InvalidResult("TIME_RESOLUTION was invalid"); } //Return the string return time;