Except an exception AND all its subclasses?

Gerrit Holl gerrit.holl at pobox.com
Sat Feb 12 04:30:39 EST 2000


Moshe Zadka wrote on 950310143:
> On Fri, 11 Feb 2000, Gerrit Holl wrote:
> 
> > Hello,
> > 
> > it's not possible to catch an exception and all its subclasses as
> > of python 1.5.2, is it?
> > 
> > I think this would be a nice feature for a future version of Python.
> > What do you think?
> 
> Why, yes, Gerrit.
> 
> -- Hey Barry! Stop trying to be your own father and let me use the time
>    machine for a second.

Huh?

> class A:
> 	pass
> 
> class B(A):
> 	pass
> 
> try:
> 	raise B
> except A:
> 	print "caught it"
> 
> Ouch! Barry, why didn't you want me about that step?

Cool!
This isn't mentioned in any book I read, neither in the tutorial. It is
mentoined in the library reference, OK.

   For class exceptions, in a try statement with an except clause that
   mentions a particular class, that clause also handles any exception
   classes derived from that class (but not exception classes from which
   it is derived). Two exception classes that are not related via
   subclassing are never equivalent, even if they have the same name.

But I think it should really be mentoined in the tutorial, since I did
not feel the need to read this in detail after I read the tutorial.

regards,
Gerrit.

-- 
Homepage: http://www.nl.linux.org/~gerrit
-----BEGIN GEEK CODE BLOCK----- http://www.geekcode.com
Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O
!M !V PS+ PE? Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK----- moc.edockeeg.www//:ptth




More information about the Python-list mailing list