I want something like this:
trigger = True
try:
x = my_function() # This can raise IndexError
if x is None:
raise ValueError
except IndexError:
trigger = False
raise ValueError
except ValueError:
do_something()
I want trigger
to be False when IndexError is raised, and do_something()
to happen both if IndexError is raised, or the return value of my_function()
is None. How can I achieve this?