[Python-ideas] Extending error handling on with statements.
Mike Meyer
mwm at mired.org
Mon Mar 28 04:54:58 CEST 2011
On Mon, 28 Mar 2011 01:18:54 +0200
Jan Kaliszewski <zuo at chopin.edu.pl> wrote:
> I don't like the idea of that magic goto.
>
> But:
>
> with ...:
> ...
> except ...:
> ...
> ...
>
> as a shortcut for:
>
> try:
> with ...:
> ...
> except ...:
> ...
> ...
>
> IMHO seems to be worth considering.
I've played around with this kind of thing in the past, and always
eventually decided there wasn't a nice way to handle all the various
desirable uses. The with statement has two bits of code, and wraps a
try/finally around one of them. You might legitimately want to handle
exceptions in either bit of code differently. Which means there are
three things you might reasonably want an except clause on a with
statement to do:
1) Wrap the entire statement (what Jan proposed).
2) Wrap the block contained by the with.
3) Be part of the try/finally implied by the with.
On the other hand, the concept of "magic goto" does generate another
idea (and hence another post).
<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/consulting.html
Independent Software developer/SCM consultant, email for more information.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
More information about the Python-ideas
mailing list