Exceptions as New Style Classes
Steven Taschuk
staschuk at telusplanet.net
Thu Jul 31 21:15:38 EDT 2003
Quoth Carl Banks:
> Steven Taschuk wrote:
> > Quoth Carl Banks:
[...]
> >> Why not give exceptions their own metaclass? So if type(x) is
> >> ExceptionMetaclass, it's a class. If type(type(x)) is
> >> ExceptionMetaclass, it's an instance. Otherwise, it's illegal to
> >> raise it.
[...]
> > I'm not sure what it gains us, though, over the idea of mandatory
> > inheritance from Exception. Am I missing something?
>
> Probably not much, unless you think you want to raise exceptions that
> aren't subclasses of Exception.
I would have thought that having to raise instances of classes
which are instances of ExceptionMetaclass would be just as onerous
as having to raise instances of Exception.
class MyRaisable(Exception):
# ...
class MyRaisable(object):
__metaclass__ = ExceptionMetaclass
# ...
I suppose Exception could have behaviour you don't want, in which
case the latter might be preferable.
--
Steven Taschuk staschuk at telusplanet.net
"Our analysis begins with two outrageous benchmarks."
-- "Implementation strategies for continuations", Clinger et al.
More information about the Python-list
mailing list