swig/Examples/test-suite/exception_order.i
Karl Wette e24ec40895 Octave: add support for version 4.2
- .travis.yml:
  - ppa:kwwette/octaves has Octave version 4.2, also run C++11 tests
- configure.ac:
  - prefer Octave program "octave-cli" to "octave"
  - extract any -std=* flags from CXX, add to OCTAVE_CXXFLAGS
- Lib/typemaps/fragments.swg:
  - SWIG_isfinite_func(): extern "C++" is required as this fragment can
    end up inside an extern "C" { } block
- Lib/octave:
  - add std_wstring.i (copied from std_string.i) for C++11 tests
- Lib/octave/octrun.swg:
  - move Octave version-checking macros to octruntime.swg
  - Octave single()/double() functions now call .as_single()/.as_double()
    methods; redirect calls to __float__() method as per .scalar_value()
  - << and >> operators are no longer supported by Octave
- Lib/octave/octruntime.swg:
  - move Octave version-checking macros here for conditional #includes
  - #include interpreter.h instead of #toplev.h
  - #include call-stack.h (now needed for octave_call_stack)
  - unwind_protect is now in octave:: namespace
  - error_state and warning_state are deprecated; use try/catch to catch
    errors in feval() instead
  - always set octave_exit = ::_Exit, to try to prevent segfault on exit
- Lib/octave/octopers.swg:
  - << and >> operators are no longer supported by Octave
- Lib/octave/exception.i:
  - Add macro SWIG_RETHROW_OCTAVE_EXCEPTIONS which rethrows any
    exceptions raised by Octave >= 4.2
- Examples/test-suite/exception_order.i:
  - Use macro SWIG_RETHROW_OCTAVE_EXCEPTIONS to rethrow exceptions
    raised by error() function in Octave >= 4.2
- Update Doc/Manual/Octave.html and CHANGES.current
2017-01-22 11:53:12 +13:00

148 lines
2.2 KiB
OpenEdge ABL

%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>;