Exceptions as New Style Classes
staschuk at telusplanet.net
Fri Aug 1 03:15:38 CEST 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.
__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