[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). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10827 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
2cafaf9d43
commit
761ef2b98f
3 changed files with 45 additions and 14 deletions
|
|
@ -1,6 +1,13 @@
|
||||||
Version 1.3.37 (in progress)
|
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
|
2008-09-02: wsfulton
|
||||||
[Python] Commit patch #1988296 GCItem multiple module linking issue when using
|
[Python] Commit patch #1988296 GCItem multiple module linking issue when using
|
||||||
directors.
|
directors.
|
||||||
|
|
|
||||||
|
|
@ -1,45 +1,72 @@
|
||||||
from director_exception import *
|
from director_exception import *
|
||||||
from exceptions import *
|
from exceptions import *
|
||||||
|
|
||||||
|
class MyException(Exception):
|
||||||
|
def __init__(self, a, b):
|
||||||
|
self.msg = a + b
|
||||||
|
|
||||||
class MyFoo(Foo):
|
class MyFoo(Foo):
|
||||||
def ping(self):
|
def ping(self):
|
||||||
raise NotImplementedError, "MyFoo::ping() EXCEPTION"
|
raise NotImplementedError, "MyFoo::ping() EXCEPTION"
|
||||||
|
|
||||||
class MyFoo2(Foo):
|
class MyFoo2(Foo):
|
||||||
def ping(self):
|
def ping(self):
|
||||||
return true
|
return True
|
||||||
pass # error: should return a string
|
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()
|
a = MyFoo()
|
||||||
b = launder(a)
|
b = launder(a)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
b.pong()
|
b.pong()
|
||||||
except NotImplementedError, e:
|
except NotImplementedError, e:
|
||||||
ok = 1
|
if str(e) == "MyFoo::ping() EXCEPTION":
|
||||||
|
ok = 1
|
||||||
|
else:
|
||||||
|
print "Unexpected error message: %s" % str(e)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not ok:
|
if not ok:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
ok = 0
|
|
||||||
|
|
||||||
|
# Check that the director returns the appropriate TypeError if the return type
|
||||||
|
# is wrong.
|
||||||
|
ok = 0
|
||||||
a = MyFoo2()
|
a = MyFoo2()
|
||||||
b = launder(a)
|
b = launder(a)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
b.pong()
|
b.pong()
|
||||||
except:
|
except TypeError, e:
|
||||||
ok = 1
|
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:
|
if not ok:
|
||||||
raise RuntimeError
|
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:
|
try:
|
||||||
raise Exception2()
|
raise Exception2()
|
||||||
except Exception2:
|
except Exception2:
|
||||||
|
|
|
||||||
|
|
@ -208,10 +208,7 @@ namespace Swig {
|
||||||
swig_msg += msg;
|
swig_msg += msg;
|
||||||
}
|
}
|
||||||
if (!PyErr_Occurred()) {
|
if (!PyErr_Occurred()) {
|
||||||
swig_msg.insert(0, ": ");
|
|
||||||
PyErr_SetString(error, getMessage());
|
PyErr_SetString(error, getMessage());
|
||||||
} else {
|
|
||||||
SWIG_Python_AddErrorMsg(getMessage());
|
|
||||||
}
|
}
|
||||||
SWIG_PYTHON_THREAD_END_BLOCK;
|
SWIG_PYTHON_THREAD_END_BLOCK;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue