Writing exception to file
Posted: Tue Jun 30, 2020 5:31 pm
Hi,
I have one big while loop in my script (that calls other modules), and I want to throw one big try/except around that while loop. I'd like to catch the exception and write the error along with the location of the error to file on the Pyboard (probably in some sort of .txt file in flash or on sd). I am running the Pyboard off of external power and will not be able to monitor the REPL prompt, so I need it to write to file so that I can access it later. Are there any suggestions? Right now, I have something like:
try:
#all of the main code
except Exception as e:
writeErrorMessage(e,"Error_Message.txt")
def writeErrorMessage(self,error,fname):
f_handle = open(fname, 'w')
f_handle.write(str(error))
f_handle.close()
I have one big while loop in my script (that calls other modules), and I want to throw one big try/except around that while loop. I'd like to catch the exception and write the error along with the location of the error to file on the Pyboard (probably in some sort of .txt file in flash or on sd). I am running the Pyboard off of external power and will not be able to monitor the REPL prompt, so I need it to write to file so that I can access it later. Are there any suggestions? Right now, I have something like:
try:
#all of the main code
except Exception as e:
writeErrorMessage(e,"Error_Message.txt")
def writeErrorMessage(self,error,fname):
f_handle = open(fname, 'w')
f_handle.write(str(error))
f_handle.close()