QFi
QFi

Reputation: 291

Continue while loop when the function catches exception

I have multiple functions inside a while loop. Each of these functions has a try/except block to catch Exception. Basically, my while loop is perpetual, so if one of my functions catches an Exception, I would like to continue the loop, i.e. go back to the top of the loop. How can this be done, please?

As I have many functions that are called within the while loop, I prefer not to have the try/except blocks outside the functions as I would have so many blocks inside the main loop (or script).

Upvotes: 0

Views: 500

Answers (1)

Daniel Lee
Daniel Lee

Reputation: 149

I'm pretty sure you would have to surround your functions in your while loop with a try/except block.

If the functions themselves have a try/except block within them and they are still being raised as errors in your while loop, I would assume your try/except block in your functions are not robust enough and it is not catching all the possible exceptions/errors.

Upvotes: 1

Related Questions