fix precatching exception behaviour to postcatching
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5617 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d6a9dfa874
commit
b32024f2ab
3 changed files with 77 additions and 37 deletions
|
|
@ -2,30 +2,53 @@
|
||||||
|
|
||||||
%include "exception.i"
|
%include "exception.i"
|
||||||
|
|
||||||
#if 1
|
|
||||||
|
/*
|
||||||
|
last resource, catch everything but don't override
|
||||||
|
user's throw declarations.
|
||||||
|
*/
|
||||||
%exception {
|
%exception {
|
||||||
try {
|
try {
|
||||||
$action
|
$action
|
||||||
} catch(...) {
|
} catch(...) {
|
||||||
SWIG_exception(SWIG_RuntimeError,"Unknown exception");
|
SWIG_exception(SWIG_RuntimeError,"postcatch unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
|
struct E1
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
struct E
|
struct E2
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
struct E3
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
struct A
|
struct A
|
||||||
{
|
{
|
||||||
int foo() throw(E)
|
/* catched by the user's throw definition */
|
||||||
{
|
int foo() throw(E1)
|
||||||
throw E();
|
{
|
||||||
return 0;
|
throw E1();
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bar() throw(E2)
|
||||||
|
{
|
||||||
|
throw E2();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* catched by the %postexception */
|
||||||
|
int foobar()
|
||||||
|
{
|
||||||
|
throw E3();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,21 @@ a = exception_order.A()
|
||||||
try:
|
try:
|
||||||
a.foo()
|
a.foo()
|
||||||
except RuntimeError,e:
|
except RuntimeError,e:
|
||||||
if e.args[0] != "E":
|
if e.args[0] != "E1":
|
||||||
print "bad exception order",
|
print "bad exception order",
|
||||||
raise RuntimeError, e.args
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -393,11 +393,31 @@ void emit_action(Node *n, Wrapper *f) {
|
||||||
}
|
}
|
||||||
/* Exception handling code */
|
/* Exception handling code */
|
||||||
|
|
||||||
|
/* saves action -> eaction for postcatching exception */
|
||||||
|
String *eaction = NewString("");
|
||||||
|
|
||||||
/* If we are in C++ mode and there is a throw specifier. We're going to
|
/* If we are in C++ mode and there is a throw specifier. We're going to
|
||||||
enclose the block in a try block */
|
enclose the block in a try block */
|
||||||
|
if (throws) {
|
||||||
|
Printf(eaction,"try {\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
Printv(eaction, action, "\n",NIL);
|
||||||
|
|
||||||
if (throws) {
|
if (throws) {
|
||||||
Printf(f->code,"try {\n");
|
Printf(eaction,"}\n");
|
||||||
|
for (Parm *ep = throws; ep; ep = nextSibling(ep)) {
|
||||||
|
String *em = Swig_typemap_lookup_new("throws",ep,"_e",0);
|
||||||
|
if (em) {
|
||||||
|
Printf(eaction,"catch(%s) {\n", SwigType_str(Getattr(ep,"type"),"&_e"));
|
||||||
|
Printv(eaction,em,"\n",NIL);
|
||||||
|
Printf(eaction,"}\n");
|
||||||
|
} else {
|
||||||
|
Swig_warning(WARN_TYPEMAP_THROW, Getfile(n), Getline(n),
|
||||||
|
"No 'throw' typemap defined for exception type '%s'\n", SwigType_str(Getattr(ep,"type"),0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Printf(eaction,"catch(...) { throw; }\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look for except typemap (Deprecated) */
|
/* Look for except typemap (Deprecated) */
|
||||||
|
|
@ -407,33 +427,18 @@ void emit_action(Node *n, Wrapper *f) {
|
||||||
if (!tm) {
|
if (!tm) {
|
||||||
tm = Getattr(n,"feature:except");
|
tm = Getattr(n,"feature:except");
|
||||||
if (tm) tm = Copy(tm);
|
if (tm) tm = Copy(tm);
|
||||||
}
|
}
|
||||||
if ((tm) && Len(tm) && (Strcmp(tm,"1") != 0)) {
|
if ((tm) && Len(tm) && (Strcmp(tm,"1") != 0)) {
|
||||||
Replaceall(tm,"$name",Getattr(n,"name"));
|
Replaceall(tm,"$name",Getattr(n,"name"));
|
||||||
Replaceall(tm,"$symname", Getattr(n,"sym:name"));
|
Replaceall(tm,"$symname", Getattr(n,"sym:name"));
|
||||||
Replaceall(tm,"$function", action);
|
Replaceall(tm,"$function", eaction);
|
||||||
Replaceall(tm,"$action", action);
|
Replaceall(tm,"$action", eaction);
|
||||||
Printv(f->code,tm,"\n", NIL);
|
Printv(f->code,tm,"\n", NIL);
|
||||||
Delete(tm);
|
Delete(tm);
|
||||||
} else {
|
} else {
|
||||||
Printv(f->code, action, "\n",NIL);
|
Printv(f->code,eaction,"\n",NIL);
|
||||||
}
|
|
||||||
|
|
||||||
if (throws) {
|
|
||||||
Printf(f->code,"}\n");
|
|
||||||
for (Parm *ep = throws; ep; ep = nextSibling(ep)) {
|
|
||||||
String *em = Swig_typemap_lookup_new("throws",ep,"_e",0);
|
|
||||||
if (em) {
|
|
||||||
Printf(f->code,"catch(%s) {\n", SwigType_str(Getattr(ep,"type"),"&_e"));
|
|
||||||
Printv(f->code,em,"\n",NIL);
|
|
||||||
Printf(f->code,"}\n");
|
|
||||||
} else {
|
|
||||||
Swig_warning(WARN_TYPEMAP_THROW, Getfile(n), Getline(n),
|
|
||||||
"No 'throw' typemap defined for exception type '%s'\n", SwigType_str(Getattr(ep,"type"),0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Printf(f->code,"catch(...) { throw; }\n");
|
|
||||||
}
|
}
|
||||||
|
Delete(eaction);
|
||||||
|
|
||||||
/* Emit contract code (if any) */
|
/* Emit contract code (if any) */
|
||||||
if (Swig_contract_mode_get()) {
|
if (Swig_contract_mode_get()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue