KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Possible Duplicate: python: Should I use ValueError or create my own subclass to handle invalid strings? Reading Built-in Exceptions I read: All user-defined exceptions should also be derived from this class" with regards to Exception. I also see a 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.
Tags (comma-separated)
Save Edits
Cancel