I would like to create a function that takes function as an argument and list of tuples. First element of a tuple will be an error and second one, a message. Example call:
handle_error(sum, [(ValueError, 'bad value'), (AttributeError, 'attribute error')]) This errors are meant to be handled in try/except blocks. I guess that it is not possible to dynamically define number of excepts. What is best practice to perform operation ilustrated as in the pseudocode example below?
def handle_error(function, errors): try: function() for error in errors: except error[0] as e: print(error[1]) I want to achieve such behaviour to make cleaner logging in my app.