summaryrefslogtreecommitdiff
path: root/Examples/test-suite/director_exception.i
blob: 3fd3e563cd91aa3ded12d4dda70a79a622c89732 (plain)
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
%module(directors="1") director_exception

%{

#if defined(_MSC_VER)
  #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
#endif

#include <string>


// define dummy director exception classes to prevent spurious errors 
// in target languages that do not support directors.

#ifndef SWIG_DIRECTORS
namespace Swig {
class DirectorException {};
class DirectorMethodException: public Swig::DirectorException {};
}
  #ifndef SWIG_fail
    #define SWIG_fail
  #endif
#endif /* !SWIG_DIRECTORS */

%}

%include "std_string.i"

#ifdef SWIGPYTHON

%feature("director:except") {
	if ($error != NULL) {
		throw Swig::DirectorMethodException();
	}
}

%exception {
	try { $action }
	catch (Swig::DirectorException &) { SWIG_fail; }
}

#endif

#ifdef SWIGJAVA

// Default for director exception warns about unmapped exceptions now in java
// Suppress warnings for this older test
// %warnfilter(476) Bar;

// Default for java is to throw Swig::DirectorException if no
// direct:except feature.  Since methods below have exception specification
// cannot throw director exception.

// Change back to old 2.0 default behavior

%feature("director:except") {
	jthrowable $error = jenv->ExceptionOccurred();
	if ($error) {
	  // Dont clear exception, still be active when return to java execution
	  // Essentially ignore exception occurred -- old behavior.
	  return $null;
	}
}

#endif

#ifdef SWIGRUBY

%feature("director:except") {
    throw Swig::DirectorMethodException($error);
}

%exception {
  try { $action }
  catch (Swig::DirectorException &e) { rb_exc_raise(e.getError()); }
}

#endif

%feature("director") Foo;

%inline {

class Foo {
public:
  virtual ~Foo() {}
  virtual std::string ping() { return "Foo::ping()"; }
  virtual std::string pong(int val=3) { return "Foo::pong();" + ping(); }
};

Foo *launder(Foo *f) {
  return f;
}

}


%{
  struct Unknown1
  {
  };

  struct Unknown2
  {
  };
%}

%feature("director") Bar;


%inline %{
  struct Exception1
  {
  };

  struct Exception2
  {
  };

  class Base 
  {
  public:
    virtual ~Base() throw () {}
  };
  

  class Bar : public Base
  {
  public:
    virtual std::string ping() throw (Exception1, Exception2&) { return "Bar::ping()"; }
    virtual std::string pong() throw (Unknown1, int, Unknown2&) { return "Bar::pong();" + ping(); }
    virtual std::string pang() throw () { return "Bar::pang()"; }
  };
  
%}