[Python-ideas] Possible PEP regarding the use of the continue keyword in try/except blocks

Elazar elazarg at gmail.com
Mon Jan 7 01:58:33 EST 2019

I think the main issue is this: exception handling is already problematic
with its nonlocal transfer of control. Making it bidirectional makes code
even more difficult to understand. State will change "under your feet"
without any syntactic clue.

In "The Design and Evolution of C++" Bjarne Stroustroup quotes an engineer
working on a large system using such a feature extensively ; they ended up
having to rewrite every single occurrence of it because it introduced a
huge amounts of bugs. This is the reason C++ does not support resume

Newer languages go in the direction of avoiding exceptions altogether, not
adding more intricate control flow directives. This proposal is basically
about introducing goto to the language.


בתאריך יום ב׳, 7 בינו׳ 2019, 5:07, מאת Richard Damon ‏<
Richard at damon-family.org>:

> On 1/6/19 9:54 PM, simon.bordeyne wrote:
> > I knew that you can just chain try/except blocks, and it's how I do it
> > now, but the example I provided wasn't very realistic.
> >
> > Take for example the initialization of a class from a config file,
> > config file which may or may not have certain keys in it. With many
> > keys, it is very inconvenient to chain try/except blocks to handle
> > every possible case. Having the continue keyword would prove useful to
> > put several error prone lines of code into a single try block, and
> > have the execution continue as normal at tge statement after the
> > statement errored out
> >
> >
> For something like reading options from a config file, I would use a
> call that specifies the key and a value to use if the key isn't present,
> and inside that function I might use a try to handle any exception
> caused when processing the key, and it could return the default.
> For your case, it is hard to imagine what you could put in the except
> block to handle the error, as you have no idea which key threw the
> error, so you have no idea which key needs to be fixed.
> Also, what happens if the exception is thrown inside a function that is
> called, do you return to the next line of that function, or the next
> line after the function call?
> What happens if the exception happens inside a loop (that is inside the
> try)? Do you just go to the next instruction in the loop and continue
> looping?
> --
> Richard Damon
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190107/1b622cb3/attachment-0001.html>

More information about the Python-ideas mailing list