Possible Duplicate:
When to choose checked and unchecked exceptions
Hello!
So, I'm still getting comfortable regarding when to throw a checked or unchecked exception. I would like to know what others think is the most appropriate in this case:
class Correlation<T>
{
private final T object1, object2;
private final double correlationCoefficient;
public Correlation(T object1, T object2, double correlationCoefficient)
{
if(Math.abs(correlationCoefficient) > 1.0 || (object1.equals(object2) && correlationCoefficient != 1.0))
throw new IllegalArgumentException();
this.object1 = object1;
this.object2 = object2;
this.correlationCoefficient = correlationCoefficient;
}
}
So, in this case, I would like to throw a runtime exception because I cannot easily recover from a situation where the user passes in bad data. I would like to point out beforehand that I have no control over the data being passed in. If I could, I would create an interface which guarantees that the conditional in the constructor is true. However, this is a convenience class for correlations that have already been computed, so I have to trust that the user is providing accurate information.
Okay, let me know what you all think!