Python Forum

Full Version: what exception for getting list of wrong size
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
in a function that might get a list, but requires certain sizes, what exception should it raise if it gets the wrong size? the function i am writing today requires 2 or more items in the list, so it is raising an exception if len(this_list)<2:. what exception should that be? ValueError? TypeError? RunTimeError? something else?
ValueError.
would you suggest the same for a function that needs 1 or more arguments but gets called with no arguments?
I don't know about that. Note that sum() with no arguments returns a TypeError.