-1
def clear_environment():
    delete_deploy_job() # could throw an exception
    delete_filler_job() # could throw an exception
    delete_project() # could throw an exception
    delete_pods() # could throw an exception

I need all these functions to execute, even if one of them throws an exception
Which is the best approach for this ?
Thanks in advance

guest381
  • 155
  • 1
  • 2
  • 12
  • 1
    take a look here https://pythonbasics.org/try-except/ – Tranbi Aug 06 '21 at 11:02
  • Either put a `try...except` around each function call, or (better) put a `try...except` in each function... better because inside from the function you can provide a more informative log message. – BoarGules Aug 06 '21 at 11:04
  • Does this answer your question? [How to properly ignore exceptions](https://stackoverflow.com/questions/730764/how-to-properly-ignore-exceptions) – Dan Gardner Aug 06 '21 at 12:41

1 Answers1

4

You could try them in a loop:

def clear_environment():
    funcs = [delete_deploy_job, delete_filler_job, delete_project, delete_pods]
    for f in funcs:
        try:
            f()
        except Exception:
            pass
quamrana
  • 37,849
  • 12
  • 53
  • 71