I need some help/advice on the best approach to do this. I have a block of code in Python, which is basically more or less the same line (a function/method applied to different variables). Now, sometimes, depending on other things, some of those variables may not exist, causing the lines that have any of them to throw an exception.
My goal is to run the block of code allowing the lines with the existing variables to run and the others to be skipped. I have a million workarounds for this, but i wanna see if there is a "clean" way, like, using a try/exception for the "entire" block.
My idea is to do something like this, where a1, a2, a3, etc., are the variables that could or could not exist:
try:
functionx(a1)
functionx(a2)
functionx(a3)
...
except:
And somehow, to get that try/except wrap to skip the ones that don't exist, but execute the ones that exist.
Any idea?
Edit: The point is to see if, somehow, i can make the try to "continue" after it gets an exception inside its code block instead of breaking and going to the except.