Let's assume that I want to invoke some method of third party API. I want to make sure that the method returns correct result. What type of exception should be thrown when the above method returns incorrect value?
Example code:
// I use third party API
Car car = findCarById(10);
int speed = car.getSpeed();
// I assume that the value must be >= 0
if (speed < 0) {
throw new [ExceptionClass]("The speed of car cannot be less than zero");
}
Google Guava provides Verify class that thrown VerifyException but it is not a standard exception. Let's assume that I cannot use Google Guava. What type of exception should be thrown in this case? I also want to known what is an alternative to Verify class? Apache commons provides Validate class - it is suitable tool for the above goal?