using builtin exceptions

Erik Price erikprice at mac.com
Sun Mar 2 23:25:30 EST 2003


Hi,

Is it considered bad practice to appropriate the "builtin" exceptions 
that ship with the stdlib in our own programs?  For instance, 
"ValueError" is explicitly described by the documentation as being for 
the use of builtin functions only ("Raised when a built-in operation or 
function receives an argument that has the right type but an 
inappropriate value, and the situation is not described by a more 
precise exception such as IndexError."), but it's the exact same 
purpose I have in mind if I use it in my code:

###
     def __init__(self, shift_type, shift_start, shift_stop):
         if not Shift.pay_rates.has_key(shift_type):
             raise KeyError
         if shift_start > shift_stop:
             raise ValueError
         ...
###

So is this okay to do?  I ask this not strictly from a pragmatic 
perspective but also from a stylistic one....

Thanks,

Erik





-- 
Erik Price

email: erikprice at mac.com
jabber: erikprice at jabber.org






More information about the Python-list mailing list