~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Lib/exception.i

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// except.i
 
3
// Dave Beazley
 
4
// April 14, 1997
 
5
//
 
6
// This SWIG library file provides language independent exception handling
 
7
 
 
8
#ifdef AUTODOC
 
9
%section "Exception Handling Library",info,after,pre,nosort,skip=1,chop_left=3,chop_right=0,chop_top=0,chop_bottom=0
 
10
 
 
11
%text %{
 
12
%include exception.i
 
13
 
 
14
This library provides language independent support for raising scripting
 
15
language exceptions in SWIG generated wrapper code.    Normally, this is
 
16
used in conjunction with the %except directive.
 
17
 
 
18
To raise an exception, use the following function call :
 
19
 
 
20
       SWIG_exception(int exctype, char *msg);
 
21
 
 
22
'exctype' is an exception type code and may be one of the following :
 
23
 
 
24
       SWIG_MemoryError
 
25
       SWIG_IOError
 
26
       SWIG_RuntimeError
 
27
       SWIG_IndexError
 
28
       SWIG_TypeError
 
29
       SWIG_DivisionByZero
 
30
       SWIG_OverflowError
 
31
       SWIG_SyntaxError
 
32
       SWIG_ValueError
 
33
       SWIG_SystemError
 
34
       SWIG_UnknownError
 
35
 
 
36
'msg' is an error string that should be reported to the user.
 
37
 
 
38
The library is normally used in conjunction with the %except directive
 
39
as follows :
 
40
 
 
41
%except {
 
42
       try {
 
43
          $function
 
44
       } catch RangeError {
 
45
          SWIG_exception(SWIG_IndexError,"Array index out of bounds");
 
46
       } catch(...) {
 
47
          SWIG_exception(SWIG_UnknownError,"Uncaught exception");
 
48
       }
 
49
}
 
50
 
 
51
It is important to note that the SWIG_exception() function is only available
 
52
to the C code generated by SWIG.  It is not available in the scripting language
 
53
interface itself.
 
54
%}
 
55
 
 
56
#endif
 
57
 
 
58
%{
 
59
#define  SWIG_MemoryError    1
 
60
#define  SWIG_IOError        2
 
61
#define  SWIG_RuntimeError   3
 
62
#define  SWIG_IndexError     4
 
63
#define  SWIG_TypeError      5
 
64
#define  SWIG_DivisionByZero 6
 
65
#define  SWIG_OverflowError  7
 
66
#define  SWIG_SyntaxError    8
 
67
#define  SWIG_ValueError     9
 
68
#define  SWIG_SystemError   10
 
69
#define  SWIG_UnknownError  99
 
70
%}
 
71
 
 
72
#ifdef SWIGTCL8
 
73
%{
 
74
#define SWIG_exception(a,b)   { Tcl_SetResult(interp,b,TCL_VOLATILE); return TCL_ERROR; }
 
75
%}
 
76
#else
 
77
#ifdef SWIGTCL
 
78
%{
 
79
#define SWIG_exception(a,b)   { Tcl_SetResult(interp,b,TCL_VOLATILE); return TCL_ERROR; }
 
80
%}
 
81
#endif
 
82
#endif
 
83
 
 
84
#ifdef SWIGPERL5
 
85
%{
 
86
#define SWIG_exception(a,b)   croak(b)
 
87
%}
 
88
#endif
 
89
 
 
90
#ifdef SWIGPERL4
 
91
%{
 
92
#define SWIG_exception(a,b)   fatal(b)
 
93
%}
 
94
#endif
 
95
 
 
96
#ifdef SWIGPYTHON
 
97
%{
 
98
static void _SWIG_exception(int code, char *msg) {
 
99
  switch(code) {
 
100
  case SWIG_MemoryError:
 
101
    PyErr_SetString(PyExc_MemoryError,msg);
 
102
    break;
 
103
  case SWIG_IOError:
 
104
    PyErr_SetString(PyExc_IOError,msg);
 
105
    break;
 
106
  case SWIG_RuntimeError:
 
107
    PyErr_SetString(PyExc_RuntimeError,msg);
 
108
    break;
 
109
  case SWIG_IndexError:
 
110
    PyErr_SetString(PyExc_IndexError,msg);
 
111
    break;
 
112
  case SWIG_TypeError:
 
113
    PyErr_SetString(PyExc_TypeError,msg);
 
114
    break;
 
115
  case SWIG_DivisionByZero:
 
116
    PyErr_SetString(PyExc_ZeroDivisionError,msg);
 
117
    break;
 
118
  case SWIG_OverflowError:
 
119
    PyErr_SetString(PyExc_OverflowError,msg);
 
120
    break;
 
121
  case SWIG_SyntaxError:
 
122
    PyErr_SetString(PyExc_SyntaxError,msg);
 
123
    break;
 
124
  case SWIG_ValueError:
 
125
    PyErr_SetString(PyExc_ValueError,msg);
 
126
    break;
 
127
  case SWIG_SystemError:
 
128
    PyErr_SetString(PyExc_SystemError,msg);
 
129
    break;
 
130
  default:
 
131
    PyErr_SetString(PyExc_RuntimeError,msg);
 
132
    break;
 
133
  }
 
134
}
 
135
 
 
136
#define SWIG_exception(a,b) { _SWIG_exception(a,b); return NULL; }
 
137
%}
 
138
#endif
 
139
 
 
140
#ifdef SWIGGUILE
 
141
%{
 
142
  static void _SWIG_exception (int code, const char *msg,
 
143
                               const char *subr) {
 
144
#define ERROR(scmerr)                                   \
 
145
        scm_error(gh_symbol2scm((char *) (scmerr)),     \
 
146
                  (char *) subr, (char *) msg,          \
 
147
                  SCM_EOL, SCM_BOOL_F)
 
148
#define MAP(swigerr, scmerr)                    \
 
149
        case swigerr:                           \
 
150
          ERROR(scmerr);                        \
 
151
          break
 
152
    switch (code) {
 
153
      MAP(SWIG_MemoryError,     "swig-memory-error");
 
154
      MAP(SWIG_IOError,         "swig-io-error");
 
155
      MAP(SWIG_RuntimeError,    "swig-runtime-error");
 
156
      MAP(SWIG_IndexError,      "swig-index-error");
 
157
      MAP(SWIG_TypeError,       "swig-type-error");
 
158
      MAP(SWIG_DivisionByZero,  "swig-division-by-zero");
 
159
      MAP(SWIG_OverflowError,   "swig-overflow-error");
 
160
      MAP(SWIG_SyntaxError,     "swig-syntax-error");
 
161
      MAP(SWIG_ValueError,      "swig-value-error");
 
162
      MAP(SWIG_SystemError,     "swig-system-error");
 
163
    default:
 
164
      ERROR("swig-error");
 
165
    }
 
166
#undef ERROR
 
167
#undef MAP
 
168
  }
 
169
 
 
170
#define SWIG_exception(a,b) _SWIG_exception(a, b, FUNC_NAME)
 
171
%}
 
172
#endif
 
173
 
 
174
#ifdef SWIGMZSCHEME
 
175
 
 
176
%{
 
177
  static void _SWIG_exception (int code, const char *msg) {
 
178
#define ERROR(errname)                          \
 
179
        scheme_signal_error(errname " (%s)", msg);
 
180
#define MAP(swigerr, errname)                   \
 
181
        case swigerr:                           \
 
182
          ERROR(errname);                       \
 
183
          break
 
184
    switch (code) {
 
185
      MAP(SWIG_MemoryError,     "swig-memory-error");
 
186
      MAP(SWIG_IOError,         "swig-io-error");
 
187
      MAP(SWIG_RuntimeError,    "swig-runtime-error");
 
188
      MAP(SWIG_IndexError,      "swig-index-error");
 
189
      MAP(SWIG_TypeError,       "swig-type-error");
 
190
      MAP(SWIG_DivisionByZero,  "swig-division-by-zero");
 
191
      MAP(SWIG_OverflowError,   "swig-overflow-error");
 
192
      MAP(SWIG_SyntaxError,     "swig-syntax-error");
 
193
      MAP(SWIG_ValueError,      "swig-value-error");
 
194
      MAP(SWIG_SystemError,     "swig-system-error");
 
195
    default:
 
196
      ERROR("swig-error");
 
197
    }
 
198
#undef ERROR
 
199
#undef MAP
 
200
  }
 
201
 
 
202
#define SWIG_exception(a,b) _SWIG_exception(a, b)
 
203
%}
 
204
#endif
 
205
 
 
206
#ifdef SWIGJAVA
 
207
%{
 
208
static void SWIG_JavaException(JNIEnv *jenv, int code, const char *msg) {
 
209
  SWIG_JavaExceptionCodes exception_code = SWIG_JavaUnknownError;
 
210
  switch(code) {
 
211
  case SWIG_MemoryError:
 
212
    exception_code = SWIG_JavaOutOfMemoryError;
 
213
    break;
 
214
  case SWIG_IOError:
 
215
    exception_code = SWIG_JavaIOException;
 
216
    break;
 
217
  case SWIG_SystemError:
 
218
  case SWIG_RuntimeError:
 
219
    exception_code = SWIG_JavaRuntimeException;
 
220
    break;
 
221
  case SWIG_OverflowError:
 
222
  case SWIG_IndexError:
 
223
    exception_code = SWIG_JavaIndexOutOfBoundsException;
 
224
    break;
 
225
  case SWIG_DivisionByZero:
 
226
    exception_code = SWIG_JavaArithmeticException;
 
227
    break;
 
228
  case SWIG_SyntaxError:
 
229
  case SWIG_ValueError:
 
230
  case SWIG_TypeError:
 
231
    exception_code = SWIG_JavaIllegalArgumentException;
 
232
    break;
 
233
  case SWIG_UnknownError:
 
234
  default:
 
235
    exception_code = SWIG_JavaUnknownError;
 
236
    break;
 
237
  }
 
238
  SWIG_JavaThrowException(jenv, exception_code, msg);
 
239
}
 
240
#define SWIG_exception(code, msg) { SWIG_JavaException(jenv, code, msg); }
 
241
%}
 
242
#endif // SWIGJAVA
 
243
 
 
244
/* exception.i ends here */