I have a code where I am supposed to call different functions based on conditions. Below is my code
try:
if condition_1 is True:
function1()
if condition_2 is True:
function2()
if condition_3 is True:
function3()
except Exception, e:
raise e
There are cases when multiple conditions can be true. So multiple function needs to be called and executed. It worked fine until today when 1 of the function raised an exception.
condition_1
and condition_3
were true. So function1
and function3
were supposed to be executed.
When it called function1
, because of some error in function1
, it raised an exception, without executing function3
. What I wanted, is that even if function1
raises error, it should still continue and check other conditions and execute respective functions accordingly.
1 way to resolve this is to write each if condition in separate try/catch block. But, is there a better way to resolve this?