[Python-Dev] Chained Exceptions
Guido van Rossum
gvanrossum at gmail.com
Fri May 13 03:31:20 CEST 2005
[Guido]
> > What if that method catches that exception?
[Ka-Ping Yee]
> Did you mean something like this?
>
> def handle():
> try:
> open('spamspamspam')
> except:
> catchit()
> # point A
> ...
>
> def catchit():
> try:
> 1/0
> except:
> pass
>
> Then there's no exception to propagate, so it doesn't matter.
> Once we're get to point A, the division by zero is long forgotten.
But at what point does the attaching happen? If I catch the
ZeroDivisionException inside catchit() and inspects its context
attribute, does it reference the IOError instance raised by
open('spamspamspam')? This could potentially cause a lot of extra
work: when an inner loop that raises and catches lots of exceptions is
invoked in the context of having caught an exception at some outer
level, the inner loop keeps attaching the outer exception to each
exception raised.
> Yes, though i did not expect to provide any mechanism for distinguishing
> the two cases. Do you think such a mechanism would be necessary?
No, I was just trying to figure out what you meant when you said
"raise". It's clear now.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev
mailing list