Which exception to use?

James Kew james.kew at btinternet.com
Tue Jan 28 19:00:09 EST 2003


Edward C. Jones wrote:
> Which exception is it best to use in the following pieces of code?
>
> if len(sys.argv) != 2:
>      raise SomeException, 'program requires exactly one argument'

How about SystemExit?

> if len(sometuple) != 3:
>      raise SomeException, 'sometuple must have length 3'
>
> I use TypeError or ValueError but they don't feel right.

I'd lean towards ValueError here: it seems to me the length of a tuple is
part of its value.

--
James Kew
james.kew at btinternet.com






More information about the Python-list mailing list