I need access to error info inside of an except in a Python script. How do I get that? Specifically, I'm executing an Oracle stored procedure, and if I catch an exception, I want to include the error message in the return value. Here's a greatly simplified example using sys.exc_info if I could actually import and use it: import sys try: context.my_proc print 'OK' except: print 'Error: ' + sys.exc_info()[1] return printed Is there a Zope-ish way to access the info returned by exc_info()? Thanks, Jim
From: "Jim Cain" <jcain@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
Jim Cain wrote at 2004-6-7 15:35 -0400:
I need access to error info inside of an except in a Python script. How do I get that?
You must learn how to allow imports and class access. You find information in the "README" file of the "PythonScripts" product and in the Zope Developer Guide. -- Dieter
participants (3)
-
Dieter Maurer -
Jim Cain -
Small Business Services