You can use a dictionary to map exceptions to functions to call:
exception_map = { ErrorTypeA : bar, ErrorTypeB : baz } try: try: somthing() except tuple(exception_map), e: # this catches only the exceptions in the map exception_map[type(e)]() # calls the related function raise # raise the Excetion again and the next line catches it except Exception, e: # every Exception ends here foobar()
source share