I'm trying to write the traceback stack of an exception that is thrown into a log file, but currently all that's written is simply a "None" :-/Don't inherit from Exception - you should be able to log *any* exception, not only this specific one, I presume? print_exc writes "the exception currently being handled", not the one you're creating right now. Put the code above into your exception handler:
Here's some example code of what I'm doing:
Import traceback
class myException(Exception):
def __init__(self):
f = open('filename.txt', 'a')
traceback.print_exc(file=f)
f.close()
The file handling (opening etc) works ok (I'm using the same file in combination with a Logger() object too) but the string written to the file is effectively just a "None".
Could anyone explain to me how to properly use the traceback module with it's countless of functions? =)
try:
1/0
except:
f = open('filename.txt', 'a')
traceback.print_exc(file=f)
f.close()
(or define a function and call it from the exception handler)
--
Gabriel Genellina