Added some exception handling

This commit is contained in:
2020-08-24 14:27:48 -04:00
parent fe80d93bdf
commit 9eb1539c07
3 changed files with 20 additions and 7 deletions

View File

@@ -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

View File

@@ -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){
}
}
}

View File

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