I'm cleaning up some code, and have run into a handful of situations where there are repetitive cleanup actions in a try/except :
try: ...except KeyError , e : cleanup_a() cleanup_b() cleanup_c() handle_keyerror()except ValuesError , e : cleanup_a() cleanup_b() cleanup_c() handle_valueerror()
i'd like to make these a bit more standardized for readability and maintenance. the "cleanup" actions seem to be local to the block , so it's not going to be much cleaner to do the following (though it will standardize it a bit):
def _cleanup_unified(): cleanup_a() cleanup_b() cleanup_c()try: ...except KeyError , e : _cleanup_unified() handle_keyerror()except ValuesError , e : _cleanup_unified() handle_valueerror()
can anyone suggest alternate ways of approaching this ?