Which exception to use?
Peter Hansen
peter at engcorp.com
Tue Jan 28 14:36:30 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'
>
> if len(sometuple) != 3:
> raise SomeException, 'sometuple must have length 3'
>
> I use TypeError or ValueError but they don't feel right. I wish there
> was a SizeError or LengthError.
IndexError? If you wish to use that, you don't even need to
do the test yourself. ;-)
By the way, I believe "raise SomeException('program blah blah')" is
the more correct way of expressing the above.
-=Peter
More information about the Python-list
mailing list