fix precatching exception behaviour to postcatching

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5617 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-01-12 23:40:58 +00:00
commit 386d53ce62
3 changed files with 77 additions and 37 deletions

View file

@ -2,30 +2,53 @@
%include "exception.i"
#if 1
/*
last resource, catch everything but don't override
user's throw declarations.
*/
%exception {
try {
$action
} catch(...) {
SWIG_exception(SWIG_RuntimeError,"Unknown exception");
}
try {
$action
} catch(...) {
SWIG_exception(SWIG_RuntimeError,"postcatch unknown");
}
}
#endif
%inline %{
struct E1
{
};
struct E
struct E2
{
};
struct E3
{
};
struct A
{
int foo() throw(E)
{
throw E();
return 0;
}
/* catched by the user's throw definition */
int foo() throw(E1)
{
throw E1();
return 0;
}
int bar() throw(E2)
{
throw E2();
return 0;
}
/* catched by the %postexception */
int foobar()
{
throw E3();
return 0;
}
};
%}

View file

@ -6,9 +6,21 @@ a = exception_order.A()
try:
a.foo()
except RuntimeError,e:
if e.args[0] != "E":
if e.args[0] != "E1":
print "bad exception order",
raise RuntimeError, e.args
try:
a.bar()
except RuntimeError,e:
if e.args[0] != "E2":
print "bad exception order",
raise RuntimeError, e.args
try:
a.foobar()
except RuntimeError,e:
if e.args[0] != "postcatch unknown":
print "bad exception order",
raise RuntimeError, e.args