Python Forum
which exception should be thrown for a sequence of the wrong length?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
which exception should be thrown for a sequence of the wrong length?
#1
which exception should be thrown for the case of passing, to a function, a sequence of the wrong length? TypeError and ValueError both seem wrong and there is no LengthError.
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, because there is an error with the value, wrong length, not the type.

You can make your own exception classes.
Gribouillis likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 6,574 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Pytest API Post call thrown errors pyseeker 4 6,087 Dec-08-2019, 04:53 PM
Last Post: pyseeker
  python gives wrong string length and wrong character thienson30 2 4,726 Oct-15-2019, 08:54 PM
Last Post: Gribouillis
  Invalid argument error thrown. pyseeker 4 10,436 Sep-10-2019, 07:03 PM
Last Post: pyseeker
  ValueError: dictionary update sequence element #0 has length 1; 2 Jmekubo 4 42,709 Apr-28-2019, 07:25 PM
Last Post: Jmekubo
  During handling of the above exception, another exception occurred Skaperen 7 32,543 Dec-21-2018, 10:58 AM
Last Post: Gribouillis
  pytest fixture in conftest.py thrown error while in the test file runs OzzieOzzum 1 5,979 Jul-31-2018, 12:12 PM
Last Post: OzzieOzzum
  [split] Teacher (thrown in at the deep end - help) Mr90 2 4,365 May-23-2018, 02:04 PM
Last Post: DeaD_EyE
  Teacher (thrown in at the deep end - help) Mr90 5 5,722 May-22-2018, 01:08 PM
Last Post: DeaD_EyE
  Exception not thrown in python3 ONEoo7 7 8,366 Apr-09-2017, 01:58 AM
Last Post: snippsat

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.