title: How does one indicate invalid arguments in Python?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1992006/python-should-i-use-valueerror-or-create-my-own-subclass-to-handle-invalid-strin">python: Should I use ValueError or create my own subclass to handle invalid strings?</a>  </p>
  </blockquote>
  
  
  
  <p>Reading <a href="http://docs.python.org/library/exceptions.html" rel="nofollow noreferrer">Built-in Exceptions</a> I read:</p>
  
  <blockquote>
    <p>All user-defined exceptions should also be derived from this class" with regards to Exception.</p>
  </blockquote>
  
  <p>I also see a <a href="http://docs.python.org/library/exceptions.html#exceptions.ValueError" rel="nofollow noreferrer">ValueError</a> which says:</p>
  
  <blockquote>
    <p>Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError.</p>
  </blockquote>
  
  <p>If I want to raise an exception for invalid arguments (the equivalent of Ruby's ArgumentError), what should I do? Should I raise <code>ValueError</code> directly, or preferably subclass ValueError with my own intention revealing name?</p>
  
  <p>In my case, I accept a key argument, but I want to restrict the set of characters in the key, such that only <code>/\A[\w.]+\Z/</code> (Perl/Ruby regular expression) is accepted.</p>