I've got a function that's supposed to add up a bunch of generics, if possible. Otherwise, it returns the value of the last generic it saw. I'd like to loop through my list of generics, try adding them, and then catch an exception if/when they can't be added. I understand that you can't try any opperators on a generic, but I can't understand why. Isn't attempting a certain method that may fail exactly why try catch was build for?
I'm pretty sure there isn't an easy way around this, but if there is, let me know.
Also, the offending code:
T getValueAtTime(float time)
{
T toReturn = officalValue.Value;
float maxValue;
velocities.Sort();
foreach(ValueAtTime<T> toAdd in velocities)
{
if(toAdd.AtTime < time)
{
try
{
toReturn += toAdd.Value;
}
catch(OpperatorUnavailableError err)
{
toReturn = toReturn + toAdd.Value;
}
catch(Exception ex)
{
toReturn = toAdd.Value;
}
}
}
return toReturn;
}