[Python-3000] self-contained exceptions
Greg Falcon
veloso at verylowsodium.com
Wed Jan 10 18:53:23 CET 2007
On 1/10/07, Josiah Carlson <jcarlson at uci.edu> wrote:
> According to the translation rules Colin has previously provided...
>
> re = get_resource()
> ...
> try:
> something()
> except RareException as re:
> ...
> ...
> re.use_resource()
>
> is translated into...
>
> re = get_resource()
> ...
> try:
> try:
> something()
> except RareException:
> re = <current exception>
> ...
> finally:
> re = None
> del re
> ...
> re.use_resource()
That's not what I understand the transformation to be. I thought the
transformation we were talking about was:
re = get_resource()
...
try:
something()
except RareException, re:
try:
...
finally:
re = None
del re
...
re.use_resource()
Per these rules:
On 1/7/07, Collin Winter <collinw at gmail.com> wrote:
> > On 1/4/07, Phillip J. Eby <pje at telecommunity.com> wrote:
> > > except ExcType, e:
> > > try:
> > > # body
> > > finally:
> > > e = None
> > > del e
> The transformation is as Phillip outlined above, with extra logic to
> handle the case where e is a tuple or list.
Perhaps the example transformation you provided is better, in that at
least you can't make the mistake I'm worried about. But it seems a
bit gratuitous (and expensive) to delete N variables when there are N
except clauses.
In any event, if I was mistaken about the transformation that occurs,
I apologize and withdraw my SyntaxWarning suggestion.
Greg F
More information about the Python-3000
mailing list