title: What is the correct way to limit the range of values a property will accept?
body: <p>I have a user control with some public properties. A particular property is an integer, but must only accept positive values that are less than a <code>const</code> max value. At present I do the following:</p>
  
  <pre><code>private int markerwidth = 2;
  [DefaultValue(2), Category("Appearance"), Description("Size of position marker")]
  public int MarkerWidth
  {
      get
      {
          return this.markerwidth;
      }
      set
      {
          if (value &gt; 0 &amp;&amp; value &lt;= MAXMARKERWIDTH)
          {
              this.markerwidth = value;
          }
      }
  }
  </code></pre>
  
  <p>This does the job, but fails silently. I guess I could add logic to use 0 for negative values and the max value for those that exceed it, but it's still not ideal.</p>
  
  <p>By way of contrast, the TabValue property (inherited from <code>UserControl</code>) complains if I try to set a negative value at design time (and presumably at run time).</p>
  
  <p>If this achieved with a normal exception? Or is there a better way? An attribute maybe?</p>