throwing an exception in a setter (java)
<p>I'm creating a Cylinder class that calculates the volume and surface area of a cylinder object created in a test class that extends the Cylinder class, and want to know how I can test that the values passed through, as radius and height, are positive. I'm attempting to do this in the setter, and have the following java code </p>

<pre><code>// only sets radius if it is a positive number
public void setRadius(double radius) {

    if (radius &lt; 0.0) {
        throw new IllegalArgumentException("Can't have a negative radius.");
    }
    this.radius = radius;
}

public double getHeight() {
    return height;
}

// only sets height if it is a positive number
public void setHeight(double height) {
    if (height &lt; 0.0) {
        throw new IllegalArgumentException("Can't have a negative height.");
    }
    this.height = height;

}
</code></pre>
