Reputation: 5769
If I was to have the following bit of code:
try:
execfile("script.py")
except ## unsure what exception goes here...
continue:
try:
execfile("other.py")
except ## unsure what exception goes here...
continue:
How do I catch all errors from script.py save it to file and then continue onto the next called script
Anyone have any ideas or clues?
Upvotes: 0
Views: 344
Reputation: 2087
import traceback # This module provides a standard interface to extract,
# format and print stack traces of Python programs.
try:
execfile("script.py")
except:
traceback.print_exc(file=open('script.traceback.txt', 'w')) # Writing exception with traceback to file script.traceback.txt
# Here is the code that will work regardless of the success of running a script.py
Upvotes: 1
Reputation: 3106
errors = open('errors.txt', 'w')
try:
execfile("script.py")
except Exception as e:
errors.write(e)
try:
execfile("other.py")
except Exception as e:
errors.write(e)
errors.close()
Upvotes: 2