I am trying to figure out a way to limit an int parameter when calling a giving function as long as the int value is within a certain range. For example:
class A{
void doSomething(int nValueWithin10And214){}
}
class B{
A objA = new A();
objA.doSomething(int someValue) //Here already know the limitation of the parameter
}
I already know to check inside the function if the parameter is within a range, but I'm looking a way when the caller already knows the limitation.
Should I create a custom throwable in these cases and the caller throws an exception when it's not within the range?
Should I create a custom object extending an Integer so the function called and the caller already comply with the requirements?
What would be the recommended way?
Any thoughts?