Python Forum

Full Version: what exception for a bad function call
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i am (re-)writing a complex function with many variations of bad ways to call it.  in cases where a bad type is given i raise a TypeError.  for values out of range or just wrong i raise a ValueError.  what should i raise for other bad cases?  i am doing more raising exceptions unless there is a programmatic reason for the caller to simply handle the unusual case, such as providing None to indicate no more of something (the function may need to turn out the lights).
Not knowing what the function does makes it difficult to 'break' it.  Python provides oodles of exceptions/errors Built in Exceptions plus you can create your own custom ones as well User defined exceptions.  Though I would imagine, if your exceptions exceed the actual program, you might be going a bit overboard  Smile