I need to make sure that in the event of any error some identical actions and some specific ones occur. Something like this:
try: doing_some_actions except SpecialErrorOne: doing_special_action1 actions_for_all_errors except SpecialErrorTwo: doing_special_action2 actions_for_all_errors except SpecialErrorThree: doing_special_action3 actions_for_all_errors How best to do this with minimal code repetition?
If you do this, the exception falls on the screen, bypassing the SpecialError'ы :
try: doing_some_actions except Exception as ex: actions_for_error raise ex except SpecialErrorOne: doing_special_action1 except SpecialErrorTwo: doing_special_action2 except SpecialErrorThree: doing_special_action3
with-construction around this block.contextlib.ExitStack()allows a variety of strategies to implement. There are many options. - jfs