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

Simon simon.bordeyne at gmail.com
Sat Jan 5 19:38:33 EST 2019


I was writing some python code earlier, and I noticed that in a code that
looks somwhat like this one :

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

>>> "invalid literal for int() with base 10: 'string'"

this code will handle the exception, but the code in the try block will not
continue.

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"
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190106/2501182b/attachment.html>


More information about the Python-ideas mailing list