Skip to content
Advertisement

python function that logs time & error when a script failed

I’m using python3. I want to print the time a script fails, as well as the corresponding exception in one line. Referring to this link & this one, I tried something like this, but the function didn’t execute. Am I doing something wrong here? Would appreciate suggestions.

JavaScript

Advertisement

Answer

Your script has multiple problems. (datetime not imported, useless try/except in f_log, …) The main issue is that a SyntaxError can’t be handled. Try this version instead:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement