PageRenderTime 19ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/exception_order.i

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