Fix exception handling when %catches is used in C#
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11583 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
d74b680a79
commit
4516c1d3f3
8 changed files with 163 additions and 23 deletions
33
Examples/test-suite/catches.i
Normal file
33
Examples/test-suite/catches.i
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
%module catches
|
||||
|
||||
%{
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#endif
|
||||
%}
|
||||
|
||||
%include <exception.i> // for throws(...) typemap
|
||||
|
||||
%catches(int, const char *, const ThreeException&) test_catches(int i);
|
||||
%catches(int, ...) test_exception_specification(int i); // override the exception specification
|
||||
%catches(...) test_catches_all(int i);
|
||||
|
||||
%inline %{
|
||||
struct ThreeException {};
|
||||
void test_catches(int i) {
|
||||
if (i == 1) {
|
||||
throw int(1);
|
||||
} else if (i == 2) {
|
||||
throw (const char *)"two";
|
||||
} else if (i == 3) {
|
||||
throw ThreeException();
|
||||
}
|
||||
}
|
||||
void test_exception_specification(int i) throw(int, const char *, const ThreeException&) {
|
||||
test_catches(i);
|
||||
}
|
||||
void test_catches_all(int i) {
|
||||
test_catches(i);
|
||||
}
|
||||
%}
|
||||
|
||||
|
|
@ -117,6 +117,7 @@ CPP_TEST_CASES += \
|
|||
arrays_scope \
|
||||
bloody_hell \
|
||||
bools \
|
||||
catches \
|
||||
cast_operator \
|
||||
casts \
|
||||
char_strings \
|
||||
|
|
|
|||
66
Examples/test-suite/csharp/catches_runme.cs
Normal file
66
Examples/test-suite/csharp/catches_runme.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using catchesNamespace;
|
||||
|
||||
public class runme {
|
||||
static void Main() {
|
||||
// test_catches()
|
||||
try {
|
||||
catches.test_catches(1);
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "C++ int exception thrown, value: 1")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
catches.test_catches(2);
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "two")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
catches.test_catches(3);
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "C++ ThreeException const & exception thrown")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
// test_exception_specification()
|
||||
try {
|
||||
catches.test_exception_specification(1);
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "C++ int exception thrown, value: 1")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
catches.test_exception_specification(2);
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "unknown exception")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
catches.test_exception_specification(3);
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "unknown exception")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
// test_catches_all()
|
||||
try {
|
||||
catches.test_catches_all(1);
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "unknown exception")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
48
Examples/test-suite/csharp/exception_order_runme.cs
Normal file
48
Examples/test-suite/csharp/exception_order_runme.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using exception_orderNamespace;
|
||||
|
||||
public class runme {
|
||||
static void Main() {
|
||||
A a = new A();
|
||||
|
||||
try {
|
||||
a.foo();
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "C++ E1 exception thrown")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
a.bar();
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "C++ E2 exception thrown")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
a.foobar();
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "postcatch unknown")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
a.barfoo(1);
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "C++ E1 exception thrown")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
|
||||
try {
|
||||
a.barfoo(2);
|
||||
throw new Exception("missed exception");
|
||||
} catch (ApplicationException e) {
|
||||
if (e.Message != "C++ E2 * exception thrown")
|
||||
throw new ApplicationException("bad exception order: " + e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue