I have an interface, let's call it IOperation
with the only Method
void Operate(TimeSpan time);
One of my implementations is due to hardware restrictions only capable of handling full milliseconds between 4 ms and 1000 ms.
1) Should I throw an exception if someone calls the method with time less than 4 or greater than 1000? If yes, is a NotSupportedException
or a ArgumentOutOfRangeException
better? Alternatively round up to 4 or down to 1000 if argument does not fit.
2) If time is between 4 and 1000 but the TotalMilliseconds property is fractional, is it OK to just round to full Milliseconds? Or throw an exception?
My favourite way would be to throw in both situations a NotSupportedException
, because according to the interface the arguments are not invalid and hence an ArgumentOutOfRangeException
does not seem to fit imho.
Furthermore internal rounding seems somehow outvoting the caller without informing him. On the other hand I feel bad about not fully fulfilling the interface contract, how should the caller react to my NotSupportedExceptions
, since Interfaces are there to give confidence to the Caller the methods are implemented according to contract