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 :
In terms of implementation, I think continue would be problematic
while true:
try:
x = foo()
return x
except:
continue
is already valid code. You'd need some way of disambiguating, either a keyword or parameter to continue. Both of which would require a very big benefit for us to do, given the ecosystem impact that such things have.
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"
Exception handling is not internally line orientated, so this proposed resume functionality doesn't map exactly. But if the following in the same way as what you envision:
def handle(f, *args):
try:
return f(*args)
except ValueError as e:
print(e)
i = handle( int, "string")
handle(print, "continued on")
Then I have to say I'm not sure what you are trying to solve. Is it the verbosity? Is it the flow control?