I have some code that iterates through a series of URLs. If there is an error in my code because one of the URLs does not contain a valid JSON body, I want the error generated to be printed to screen, but then the code moves onto the next iteration. A simple version of my code is:
for a in myurls:
try:
#mycode
except Exception as exc:
print traceback.format_exc()
print exc
pass
However this prints the error to screen and ends execution of the code. Is there a way I can get the error to continue execution by moving to the next iteration of my 'for' loop?
Just put try-except over the code for which you expect an exception to occur. That code basically lies inside the loop.
for a in myurls:
try:
#mycode
except Exception as exc:
print traceback.format_exc()
print exc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With