Where is the rest of the exception?

I could be wrong, but it seems that I get incomplete stack traces and exception messages when a SystemError occurs in IronPython. I'm doing it:

                try:
                    with SQLConnection(DATASOURCES[SCHEDULEDB]) as db:
                        db.execute_sql( command + ' ' + ','.join(block) + ';' )
                except Exception, e:
                    print 'caught an exception'
                    print "Unexpected error:", sys.exc_info()[0]
                    print e
                    raise
                finally:
                    db.close()
                    engine.close()

however, all I see is:

Traceback (most recent call last):
SystemError: The connection has been disabled.
+3
source share
2 answers

Try:

import traceback
traceback.print_exc()

Instead of directly printing the exception object. In Python exception objects, objects are not tied directly to the stack trace — instead, they are part of a trio of elements in sys.exc_info ().

You can also do:

import System
...

except System.Exception, e:

and you get a regular .NET exception object instead of a Python exception object.

+7
source

There are several flags in the IronPython process that will set .NET exceptions to reset the stack trace:

ipy -X:ShowClrExceptions -X:ExceptionDetail my_script.py args
0
source

All Articles