[Zope] Accessing sys.exc_info() from python script

Small Business Services toolkit at magma.ca
Tue Jun 8 07:52:38 EDT 2004


From: "Jim Cain" <jcain at equala.com>
> I need access to error info inside of an except in a Python script. How
> do I get that?
> Is there a Zope-ish way to access the info returned by exc_info()?

You can't do it from a python script.  You need an external method, here are
some useful bits:


import sys, traceback

        try:
               <your code here>

        except:
                etype = sys.exc_info()[0]
                evalue = sys.exc_info()[1]
                etb = traceback.extract_tb(sys.exc_info()[2])
                logfile.write('Error in routine: your routine here\n')
                logfile.write('Error Type: ' + str(etype) + '\n')
                logfile.write('Error Value: ' + str(evalue) + '\n')
                logfile.write('Traceback: ' + str(etb) + '\n')

Instead of writing to a log file, you could append the info to a string/list
variable and return it.

HTH

Jonathan





More information about the Zope mailing list