Quantcast
Viewing all articles
Browse latest Browse all 4852

Python • Re: How do I call a function if there is an error?

Using Python exceptions, 'try-except-finally' wrapper code, is what you need. Where to put those, what to wrap, what to do and how to handle program continuation, will very much depend on the particular code and application.

The simplest solution for embedded code which has to keep on running is to put your code in a 'main' routine, call that in an infinite loop and wrap that. Something like ...

Code:

def main():  ...while True:  try:    main()  except Exception as e:    ReportException(e)
But you may find you want more localised exception trapping as well.

Statistics: Posted by hippy — Wed Apr 03, 2024 2:42 pm



Viewing all articles
Browse latest Browse all 4852

Trending Articles