R: [Python-Dev] Deprecating string exceptions
Martin v. Loewis
martin@v.loewis.de
28 Mar 2002 10:35:36 +0100
barry@zope.com (Barry A. Warsaw) writes:
> Can you explain why you think the rule should be so strict? I don't
> see a problem with using multiple inheritance to satisfy the "must
> derive" rule.
The question is, whether, given
class Base:pass
class MyExc(Base, Exception):pass
it would be valid to write
try:
foo() # raises MyExc
except Base:
pass
If that ought to be allowed, I fail to see the rationale to require
that exceptions be derived from Exception: The rationale could be "all
exceptions are primarily instances of Exception" - yet in this case,
Base is the primary class, and Exception is just a mix-in that plays
no further role in this case of exception handling.
If you want to allow Base in the except clause, but do allow Base as
the base class of MyExc, I'd be curious what run-time semantics you'd
associate with this example.
Regards,
Martin