Is it possible to add a Custom Message globally on runtime-erros? I would like to have a time-stamp as this would help figuring out if a file eventually was written by that execution process.
Asked
Active
Viewed 152 times
0
-
Do you mean when the RuntimeError exception is raised? If so can't you just catch that at the top level of your process and do whatever you want? – Tom Dalton Apr 07 '16 at 00:30
2 Answers
1
Replacing sys.excepthook
with an appropriate function will allow you to do whatever you like upon every occurrence of an uncaught exception.
![](../../users/profiles/20862.webp)
Ignacio Vazquez-Abrams
- 699,552
- 132
- 1,235
- 1,283
0
Take a look at the Python docs (2, 3) on handling exceptions. You can catch the RuntimeError and print the original message along with a custom timestamp. For more information on accessing the stack trace and exception messages, check out this question.
Ignacio's solution is also great if you'd like to set the message globally.