0

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.

user1767754
  • 18,800
  • 14
  • 111
  • 133
  • 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 Answers2

1

Replacing sys.excepthook with an appropriate function will allow you to do whatever you like upon every occurrence of an uncaught exception.

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.

Community
  • 1
  • 1
samrap
  • 5,245
  • 5
  • 29
  • 55