469,927 Members | 1,589 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

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

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
0 1048

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by fowlertrainer | last post: by
reply views Thread by Ehab Teima | last post: by
2 posts views Thread by Scott Vercuski | last post: by
7 posts views Thread by Ollie | last post: by
2 posts views Thread by MattB | last post: by
12 posts views Thread by Martyn Fewtrell | last post: by
5 posts views Thread by Thomas Guettler | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.