using builtin exceptions

Tim Peters tim.one at comcast.net
Sun Mar 2 23:27:04 EST 2003


[Erik Price]
> Is it considered bad practice to appropriate the "builtin" exceptions
> that ship with the stdlib in our own programs?

No, and people routinely reuse, e.g., ValueError and KeyError and TypeError
for their own good purposes.  I think it would be crazy *not* to.  I'd stay
away from reusing SystemError and MemoryError, though -- the former because
the docs urge users to bother the Python developers when they see one
<wink>, the latter because it's really intended to pass on out-of-memory
errors from the platform malloc().  Reusing SyntaxError also seems dicey (I
expect Python to raise that when compiling code, not, e.g., when a piece of
XML is ill-formed).






More information about the Python-list mailing list