PageRenderTime 3ms CodeModel.GetById 1ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Swig | 79 lines | 70 code | 9 blank | 0 comment | 0 complexity | 7084c3c53e65902bc61e31a6717ab30a MD5 | raw file
 1%module throw_exception
 2
 3%{
 4#if defined(_MSC_VER)
 5  #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
 6#endif
 7%}
 8
 9%warnfilter(SWIGWARN_RUBY_WRONG_NAME) Namespace::enum1;
10%warnfilter(SWIGWARN_RUBY_WRONG_NAME) Namespace::enum2;
11#ifdef SWIGPHP
12%warnfilter(SWIGWARN_PARSE_KEYWORD) Namespace;
13#endif
14
15// Tests SWIG's automatic exception mechanism
16
17%inline %{
18
19class Error {
20};
21
22void test_is_Error(Error *r) {}
23
24namespace Namespace {
25  typedef Error ErrorTypedef;
26  typedef const Error& ErrorRef;
27  typedef const Error* ErrorPtr;
28  typedef int IntArray[10];
29  enum EnumTest { enum1, enum2 };
30}
31class Foo {
32public:
33    void test_int() throw(int) {
34      throw 37;
35    }
36    void test_msg() throw(const char *) {
37      throw "Dead";
38    }
39    void test_cls() throw(Error) {
40      throw Error();
41    }	
42    void test_cls_ptr() throw(Error *) {
43      static Error StaticError;
44      throw &StaticError;
45    }	
46    void test_cls_ref() throw(Error &) {
47      static Error StaticError;
48      throw StaticError;
49    }	
50    void test_cls_td() throw(Namespace::ErrorTypedef) {
51      throw Error();
52    }	
53    void test_cls_ptr_td() throw(Namespace::ErrorPtr) {
54      static Error StaticError;
55      throw &StaticError;
56    }	
57    void test_cls_ref_td() throw(Namespace::ErrorRef) {
58      static Error StaticError;
59      throw StaticError;
60    }	
61    void test_array() throw(Namespace::IntArray) {
62      static Namespace::IntArray array;
63      for (int i=0; i<10; i++) {
64        array[i] = i;
65      }
66      throw array;
67    }	
68    void test_enum() throw(Namespace::EnumTest) {
69      throw Namespace::enum2;
70    }	
71    void test_multi(int x) throw(int, const char *, Error) {
72      if (x == 1) throw 37;
73      if (x == 2) throw "Dead";
74      if (x == 3) throw Error();
75    }
76};
77
78%}
79