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

Amber Yust amber.yust at gmail.com
Sun Jan 6 03:07:31 EST 2019

On Sat, Jan 5, 2019 at 4:39 PM Simon <simon.bordeyne at gmail.com> wrote:

> I propose to be able to use the continue keyword to continue the execution
> of the try block even when an error is handled. The above could then be
> changed to :
>     try:
>         i = int("string")
>         print("continued on")
>         j = int(9.0)
>     except ValueError as e:
>         print(e)
>         continue
> >>> "invalid literal for int() with base 10: 'string'"
> >>> "continued on"

There is already a much simpler way of doing this:

        i = int("string")
    except ValueError as e:
    print("continued on")
    j = int(9.0)

The point of the 'try' block is to encapsulate the code you want to *stop*
executing if an exception is raised. If you want code to be run regardless
of whether an exception is raised, move it past the try-except.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190106/a517879f/attachment-0001.html>

More information about the Python-ideas mailing list