> 
> **Possible Duplicate:**  
> 
> [python: Should I use ValueError or create my own subclass to handle invalid strings?](https://stackoverflow.com/questions/1992006/python-should-i-use-valueerror-or-create-my-own-subclass-to-handle-invalid-strin) 
> 
> 
> 

Reading [Built-in Exceptions](http://docs.python.org/library/exceptions.html) I read:

> 
> All user-defined exceptions should also be derived from this class" with regards to Exception.
> 
> 
> 

I also see a [ValueError](http://docs.python.org/library/exceptions.html#exceptions.ValueError) which says:

> 
> 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.
> 
> 
> 

If I want to raise an exception for invalid arguments (the equivalent of Ruby's ArgumentError), what should I do? Should I raise `ValueError` directly, or preferably subclass ValueError with my own intention revealing name?

In my case, I accept a key argument, but I want to restrict the set of characters in the key, such that only `/\A[\w.]+\Z/` (Perl/Ruby regular expression) is accepted.