0

How would one capture ALL Python failures and log them into a file? Not just failures captured in a try: / except: code within the program but ALL failures. So if there was a line in the code that does not fail until that code block is reached during execution, it could be logged to a file. Existing try: / except: code in the program should continue to operate but in this case, one would wish to capture errors where one did not expect a failure to ever occur. This would be like the entire program being in a try: while try: that was written into the code would still work.

This could be used in a case where production-level code wants to run without a command console being open while being able to look at a log file to see what may have caused the program to fail.

Jay Mosk
  • 197
  • 1
  • 2
  • 8
  • as I know there is no method for this. You have only try/except to catch expected errors. Different errors may need different methods to keep code running. Some of them may need only to skip rest of code, other may need to use some default value, etc. – furas Jun 24 '22 at 13:27
  • I would not think there would be a problem in running an entire application inside a try: block. This way you would want to catch things like using a variable before it is defined, that did not come up in testing. But if you are running without a command window the package would just fail and you would not have a clue why. If you can log the error to a file you have the ability to determine why the code shut down. But I am concerned if executing a try: inside a try: works. – Jay Mosk Jun 24 '22 at 16:35

0 Answers0