By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

Re: Writing traceback of an exception into a log-file

P: n/a
En Mon, 26 May 2008 05:31:27 -0300, <Do*****************@ch.delarue.comescribió:
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" :-/

Here's some example code of what I'm doing:

Import traceback
class myException(Exception):
def __init__(self):
f = open('filename.txt', 'a')

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? =)
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:

f = open('filename.txt', 'a')

(or define a function and call it from the exception handler)

Gabriel Genellina

Jun 27 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.