Throw an exception if the value is outside the range.