Which exception to use?

Mongryong Mongryong at sympatico.ca
Tue Jan 28 16:09:04 EST 2003


For 'library API', it's probably not a good idea to be checking the
length of 'sys.argv'.  If you really need to check the length of 'some
tuple' parameter, you might be better to use 'assert' instead.  

An exception should be used for cases where an 'expected' or 'undefine'
runtime error occurs.  ie. Network connection failure.

Assertions should be used for dumb programmer errors that would be
trace-able through testing.

ie.
assert len(sometuple) == FIXED_SIZE, "Invalid paramter..tuple most be
this size..."








More information about the Python-list mailing list