title: What exception to throw from a property setter?
body: <p>I have a string property that has a maximum length requirement because the data is linked to a database. What exception should I throw if the caller tries to set a string exceeding this length?</p>
  
  <p>For example, this C# code:</p>
  
  <pre><code>public string MyProperty
  {
      get
      {
          return _MyBackingField;
      }
      set
      {
          if (value.Length &gt; 100)
              throw new FooException("MyProperty has a maximum length of 100.");
  
          _MyBackingField = value;
      }
  }
  </code></pre>
  
  <p>I considered <code>ArgumentException</code>, but it just doesn't seem right. <em>Technically</em>, it is a function - <code>MyProperty_set(string value)</code> - so a case for <code>ArgumentException</code> can be made, but it's not being called as a function to the consumer's eyes - it's on the right side of an assignment operator. </p>
  
  <p>This question could probably also be extended to include all kinds of data validation done in property setters, but I'm particularly interested in the above case.</p>