catching all exceptions

Arne Mueller a.mueller at icrf.icnet.uk
Thu Feb 8 17:34:00 CET 2001


Siggy Brentrup wrote:
> 
> Sorry for the typo :-(
> 
> Siggy Brentrup <bsb at winnegan.de> writes:
> 
> > import traceback, cStringIO
> >
> > f = cStringIO.StringIO
>   f = cStringIO.StringIO()
> > traceback.print_exc(None, f)
> >
> > write_to_database(f.getvalue())
> >
> > HTH
> >   Siggy

Thanks alot for the code above, this is what I was looking for. Also
sorry, I should have known about the traceback module - obviously didn't
read the python reference manual carefully anough ;-(

here's some code to do a test:

import sys, traceback, StringIO
x = 5

def boo(n):
    x.append(n) # raises AttributeError

try:
    boo(6)
except:
    f = StringIO.StringIO()
    print "Start"
    traceback.print_exc(None, f)
    #s = f.getvalue() # this works
    s = f.readlines() # empty array
    print s
    f.close()
    print "End"

f.readline() returns an empty array, but shouldn't have 
traceback.print_exc(None, f) filled f, so that 'readlines' can access
it?

	thanks very much,

	Arne




More information about the Python-list mailing list