1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
%module exception_order
%warnfilter(SWIGWARN_RUBY_WRONG_NAME);
#if defined(SWIGGO) && defined(SWIGGO_GCCGO)
%{
#ifdef __GNUC__
#include <cxxabi.h>
#endif
%}
#endif
%include "exception.i"
%{
#if defined(_MSC_VER)
#pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif
%}
/*
last resource, catch everything but don't override
user's throw declarations.
*/
#if defined(SWIGOCTAVE)
%exception {
try {
$action
}
SWIG_RETHROW_OCTAVE_EXCEPTIONS
catch(...) {
SWIG_exception(SWIG_RuntimeError,"postcatch unknown");
}
}
#elif defined(SWIGUTL)
%exception {
try {
$action
} catch(...) {
SWIG_exception_fail(SWIG_RuntimeError,"postcatch unknown");
}
}
#elif defined(SWIGGO) && defined(SWIGGO_GCCGO)
%exception %{
try {
$action
#ifdef __GNUC__
} catch (__cxxabiv1::__foreign_exception&) {
throw;
#endif
} catch(...) {
SWIG_exception(SWIG_RuntimeError,"postcatch unknown");
}
%}
#else
%exception {
try {
$action
} catch(...) {
SWIG_exception(SWIG_RuntimeError,"postcatch unknown");
}
}
#endif
%catches(E1,E2*,ET<int>,ET<double>,...) A::barfoo(int i);
%allowexception efoovar;
%allowexception A::efoovar;
%inline %{
int efoovar;
int foovar;
const int cfoovar = 1;
struct E1
{
};
struct E2
{
};
struct E3
{
};
template <class T>
struct ET
{
};
struct A
{
static int sfoovar;
static const int CSFOOVAR = 1;
int foovar;
int efoovar;
/* caught by the user's throw definition */
int foo() throw(E1)
{
throw E1();
return 0;
}
int bar() throw(E2)
{
throw E2();
return 0;
}
/* caught by %postexception */
int foobar()
{
throw E3();
return 0;
}
int barfoo(int i)
{
if (i == 1) {
throw E1();
} else if (i == 2) {
static E2 *ep = new E2();
throw ep;
} else if (i == 3) {
throw ET<int>();
} else {
throw ET<double>();
}
return 0;
}
};
int A::sfoovar = 1;
#ifdef SWIGPYTHON_BUILTIN
bool is_python_builtin() { return true; }
#else
bool is_python_builtin() { return false; }
#endif
%}
%template(ET_i) ET<int>;
%template(ET_d) ET<double>;
|