Exceptions as New Style Classes
Carl Banks
imbosol at aerojockey.com
Thu Jul 31 03:54:59 EDT 2003
Steven Taschuk wrote:
> Quoth Carl Banks:
>> Steven Taschuk wrote:
>> > At the moment the dominant idea for solving these problems is to
>> > make inheritance from Exception mandatory for exception types; see
> [...]
>> 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.
>
> That seems workable. (I'd prefer, though, to test
> isinstance(type(x), ExceptionMetaclass)
> and likewise for the second case.)
>
> 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.
--
CARL BANKS
More information about the Python-list
mailing list