Python Forum
what exception for getting list of wrong size
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what exception for getting list of wrong size
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
ValueError.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
would you suggest the same for a function that needs 1 or more arguments but gets called with no arguments?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
I don't know about that. Note that sum() with no arguments returns a TypeError.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020