title: Is it a good practice to throw Exception inside setters in Java?
body: <p>To be more specific, I want to write a code that throws <code>IllegalArgumentException</code> if the given value is negative. Should I include this code inside of setter/constructor or should I check the value when the appropriate method is called? (Eg: <code>start()</code>, <code>init()</code>, <code>print()</code> or <code>run()</code>. whatever.)</p>
  
  <p>My code (simplified):</p>
  
  <pre><code>public class LLUAlgorithm {
  
  private int temperature;
  
  public int getTemperature() {
      return temperature;
  }
  
  public void setTemperature(int temperature) {
      if (temperature &lt; 0)
          throw new IllegalArgumentException("can't be smaller than 0.")
      this.temperature = temperature;
  }
  
  public void run() {
      ...
  }   
  </code></pre>
  
  <p>I don't recall a single case that a setter throws an exception as above. But I'm curious if it is good / bad. </p>