My python code looks something like this -
try:
statement1
statement2
statement3
except Exception:
handleException
The problem is, if statement3 produces an exception, the effects of statement1 and statement2 have already taken place, and I can't undo them in the except
section. Is there an easy way to write something like -
check if the following block runs without exceptions:
statement1
statement2
statement3
if yes:
run entire block
if no:
handleException
(Basically something like transactional atomicity for Python code).