Cover All Exceptions: Python Error Logging

  • Context: Python 
  • Thread starter Thread starter cpscdave
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 1K views
cpscdave
Messages
402
Reaction score
120
I feel a bit dirty asking this..
But I've written a fairly large program that is going to be deployed in a few weeks. Its a headless server. I've done error checking throughout the code where I am aware of it, but I'm worried about the things I have missed.

Is there a way in python I can get it to continue on all exceptions? Perhaps write out an error log as well?? I highly doubt there is but thought I'd check :)
 
Physics news on Phys.org
Can you predict which exceptions are likely to be thrown? If so, maybe something like this is feasible:
Python:
try:
   <some code that might throw>
except (RuntimeError, TypeError, NameError):
   <handle error>
finally:
   <clean up>
 
  • Like
Likes   Reactions: cpscdave
You could double down on that slightly dirty feeling and write a program with an infinite loop that launches your server, captures stderr and diverts it to a logfile. In other words, an automatic log-it-and-reboot.
 
  • Like
Likes   Reactions: cpscdave
Ibix said:
You could double down on that slightly dirty feeling and write a program with an infinite loop that launches your server, captures stderr and diverts it to a logfile. In other words, an automatic log-it-and-reboot.

Haha that might actually not be a bad idea.
This is the classic case of I want a few weeks to test, and I have a few days :P

I'm going to add some GOTO's just to make my fall from grace complete.
And who needs comments in the code??