Python Cover All Exceptions: Python Error Logging

  • Thread starter Thread starter cpscdave
  • Start date Start date
Click For Summary
The discussion centers on concerns about error handling in a large Python program set for deployment on a headless server. The original poster seeks a method to allow the program to continue running despite exceptions, while also logging errors for later review. Suggestions include using a try-except block to handle specific exceptions like RuntimeError, TypeError, and NameError, and implementing a logging mechanism to capture stderr output. Additionally, a humorous suggestion is made to create an infinite loop that restarts the server and logs errors automatically. The conversation reflects a sense of urgency, with the poster feeling pressed for time to test the program before deployment, leading to lighthearted comments about using GOTO statements and neglecting code comments.
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 :)
 
Technology 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 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 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??
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
Replies
3
Views
1K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 43 ·
2
Replies
43
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
15K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
1K
Replies
1
Views
2K