diff --git a/CHANGES.current b/CHANGES.current index 18f565cec..6b552c994 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -1,6 +1,13 @@ Version 1.3.37 (in progress) ============================= +2008-09-02: wsfulton + [Python] Commit patch #2089149: Director exception handling mangles + returned exception. Exceptions raised by Python code in directors + are now passed through to the caller without change. Also, remove + the ": " prefix which used to be added to other director exceptions + (eg, those due to incorrect return types). + 2008-09-02: wsfulton [Python] Commit patch #1988296 GCItem multiple module linking issue when using directors. diff --git a/Examples/test-suite/python/director_exception_runme.py b/Examples/test-suite/python/director_exception_runme.py index 7c9e69250..28521ffa5 100644 --- a/Examples/test-suite/python/director_exception_runme.py +++ b/Examples/test-suite/python/director_exception_runme.py @@ -1,45 +1,72 @@ from director_exception import * from exceptions import * +class MyException(Exception): + def __init__(self, a, b): + self.msg = a + b + class MyFoo(Foo): def ping(self): raise NotImplementedError, "MyFoo::ping() EXCEPTION" class MyFoo2(Foo): def ping(self): - return true + return True pass # error: should return a string -ok = 0 +class MyFoo3(Foo): + def ping(self): + raise MyException("foo", "bar") +# Check that the NotImplementedError raised by MyFoo.ping() is returned by +# MyFoo.pong(). +ok = 0 a = MyFoo() b = launder(a) - try: b.pong() except NotImplementedError, e: - ok = 1 + if str(e) == "MyFoo::ping() EXCEPTION": + ok = 1 + else: + print "Unexpected error message: %s" % str(e) except: pass - if not ok: raise RuntimeError -ok = 0 +# Check that the director returns the appropriate TypeError if the return type +# is wrong. +ok = 0 a = MyFoo2() b = launder(a) - try: b.pong() -except: - ok = 1 - - +except TypeError, e: + if str(e) == "Swig director type mismatch in output value of type 'std::string'": + ok = 1 + else: + print "Unexpected error message: %s" % str(e) if not ok: raise RuntimeError +# Check that the director can return an exception which requires two arguments +# to the constructor, without mangling it. +ok = 0 +a = MyFoo3() +b = launder(a) +try: + b.pong() +except MyException, e: + if e.msg == 'foobar': + ok = 1 + else: + print "Unexpected error message: %s" % str(e) +if not ok: + raise RuntimeError + try: raise Exception2() except Exception2: diff --git a/Lib/python/director.swg b/Lib/python/director.swg index 7438cfbff..836d107ce 100644 --- a/Lib/python/director.swg +++ b/Lib/python/director.swg @@ -208,10 +208,7 @@ namespace Swig { swig_msg += msg; } if (!PyErr_Occurred()) { - swig_msg.insert(0, ": "); PyErr_SetString(error, getMessage()); - } else { - SWIG_Python_AddErrorMsg(getMessage()); } SWIG_PYTHON_THREAD_END_BLOCK; }