So, I have an abstract data type called RegionModel with a series of values (Region), each of which maps to an index. You can delete several areas by calling:
regionModel.removeRegions(index, numberOfRegionsToRemove);
My question is the best way to handle the call when the index is valid:
(between 0 (inclusive) and the number of areas in the model (excluding))
but the number ofOfRegionsToRemove is not valid:
(index + regionsToRemove> the number of regions in the model)
Is it better to throw an exception like IllegalArgumentException, or just delete as many areas as I can (all regions from index to end of model)?
Subprocess: if I throw an exception, what is the recommended way for the unit test that the call throws an exception and leaves the model untouched (I use Java and JUnit here, but I assume this is not a Java specific issue).
source
share