Raising objects
Andrew Dalke
adalke at mindspring.com
Wed Apr 30 14:27:29 EDT 2003
Steven Taschuk:
> But is there a problem with being able to raise anything? Perhaps
> some class of easy-to-produce bugs that I'm not seeing?
Here's my guess. Currently to catch any exception you need to do
try:
f()
except:
...look in sys.exc_info()...
Calling sys to do that is a bit of a wart, but it's the only
solution since current Python doesn't have a unified base
type.
However, if all exceptions were derived from Exception
then you could do
except Exception, e:
... use e ...
This cleans up the wart at the expense of not allowing
any old object to be thrown.
Will Python ever require that all classes be derived
from 'object'? If so, then the generic "catch everything"
would be
except object, e:
... use e ...
But that won't happen soon.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list