Writing traceback

Ehab Teima ehab_teima at hotmail.com
Tue Aug 10 19:53:15 EDT 2004


Hello,

I have built a server application. It's multithreaded, and everything
works fine so far. I have only one issue with catching exceptions
after I read the documentation but I can't find any problems yet. I'm
catching all errors throughout the code into a function and I write
the traceback to the server log as well as the screen. That's all. I
need not to save it or anything else. The documentation said the
function (in this example catchError) should not handle exceptions
itself. How would I get around this issue given that writing to the
server log must not stop the server? In other words, the function
itself must handle and ignore any exceptions raised by itself. i.e. I
want to make sure that failing to write to the server log is ignored.

The code I have looks like this:

try:
    handleClient(...)
except:
    catchError(sys.exc_info())

def catchError(excInfo):
    print 'An error occured'
    try:
        fo=open(log, "w")
        print_exc()
        print_exc(None, fo)
        fo.close()
    except:
        print 'Could not write to the server log'



More information about the Python-list mailing list