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

/trunk/Lib/exception.i

#
Swig | 308 lines | 255 code | 28 blank | 25 comment | 0 complexity | 1e1ff01eff7fde1f0364d0f497a541b2 MD5 | raw file
  1/* -----------------------------------------------------------------------------
  2 * exception.i
  3 *
  4 * SWIG library file providing language independent exception handling
  5 * ----------------------------------------------------------------------------- */
  6
  7#if defined(SWIGUTL)
  8#error "This version of exception.i should not be used"
  9#endif
 10
 11
 12%insert("runtime") "swigerrors.swg"
 13
 14
 15#ifdef SWIGPHP
 16%{
 17#if PHP_MAJOR_VERSION < 5
 18# define SWIG_exception(code, msg) { zend_error(E_ERROR, msg); }
 19#else
 20# include "zend_exceptions.h"
 21# define SWIG_exception(code, msg) { zend_throw_exception(NULL, (char*)msg, code TSRMLS_CC); }
 22#endif
 23%}
 24#endif
 25
 26#ifdef SWIGGUILE
 27%{
 28  SWIGINTERN void SWIG_exception_ (int code, const char *msg,
 29                               const char *subr) {
 30#define ERROR(scmerr)					\
 31	scm_error(gh_symbol2scm((char *) (scmerr)),	\
 32		  (char *) subr, (char *) msg,		\
 33		  SCM_EOL, SCM_BOOL_F)
 34#define MAP(swigerr, scmerr)			\
 35	case swigerr:				\
 36	  ERROR(scmerr);			\
 37	  break
 38    switch (code) {
 39      MAP(SWIG_MemoryError,	"swig-memory-error");
 40      MAP(SWIG_IOError,		"swig-io-error");
 41      MAP(SWIG_RuntimeError,	"swig-runtime-error");
 42      MAP(SWIG_IndexError,	"swig-index-error");
 43      MAP(SWIG_TypeError,	"swig-type-error");
 44      MAP(SWIG_DivisionByZero,	"swig-division-by-zero");
 45      MAP(SWIG_OverflowError,	"swig-overflow-error");
 46      MAP(SWIG_SyntaxError,	"swig-syntax-error");
 47      MAP(SWIG_ValueError,	"swig-value-error");
 48      MAP(SWIG_SystemError,	"swig-system-error");
 49    default:
 50      ERROR("swig-error");
 51    }
 52#undef ERROR
 53#undef MAP
 54  }
 55
 56#define SWIG_exception(a,b) SWIG_exception_(a, b, FUNC_NAME)
 57%}
 58#endif
 59
 60#ifdef SWIGMZSCHEME
 61
 62%{
 63SWIGINTERN void SWIG_exception_ (int code, const char *msg) {
 64#define ERROR(errname)				\
 65	scheme_signal_error(errname " (%s)", msg);
 66#define MAP(swigerr, errname)			\
 67	case swigerr:				\
 68	  ERROR(errname);			\
 69	  break
 70    switch (code) {
 71      MAP(SWIG_MemoryError,	"swig-memory-error");
 72      MAP(SWIG_IOError,		"swig-io-error");
 73      MAP(SWIG_RuntimeError,	"swig-runtime-error");
 74      MAP(SWIG_IndexError,	"swig-index-error");
 75      MAP(SWIG_TypeError,	"swig-type-error");
 76      MAP(SWIG_DivisionByZero,	"swig-division-by-zero");
 77      MAP(SWIG_OverflowError,	"swig-overflow-error");
 78      MAP(SWIG_SyntaxError,	"swig-syntax-error");
 79      MAP(SWIG_ValueError,	"swig-value-error");
 80      MAP(SWIG_SystemError,	"swig-system-error");
 81    default:
 82      ERROR("swig-error");
 83    }
 84#undef ERROR
 85#undef MAP
 86  }
 87
 88#define SWIG_exception(a,b) SWIG_exception_(a, b)
 89%}
 90#endif
 91
 92#ifdef SWIGJAVA
 93%{
 94SWIGINTERN void SWIG_JavaException(JNIEnv *jenv, int code, const char *msg) {
 95  SWIG_JavaExceptionCodes exception_code = SWIG_JavaUnknownError;
 96  switch(code) {
 97  case SWIG_MemoryError:
 98    exception_code = SWIG_JavaOutOfMemoryError;
 99    break;
100  case SWIG_IOError:
101    exception_code = SWIG_JavaIOException;
102    break;
103  case SWIG_SystemError:
104  case SWIG_RuntimeError:
105    exception_code = SWIG_JavaRuntimeException;
106    break;
107  case SWIG_OverflowError:
108  case SWIG_IndexError:
109    exception_code = SWIG_JavaIndexOutOfBoundsException;
110    break;
111  case SWIG_DivisionByZero:
112    exception_code = SWIG_JavaArithmeticException;
113    break;
114  case SWIG_SyntaxError:
115  case SWIG_ValueError:
116  case SWIG_TypeError:
117    exception_code = SWIG_JavaIllegalArgumentException;
118    break;
119  case SWIG_UnknownError:
120  default:
121    exception_code = SWIG_JavaUnknownError;
122    break;
123  }
124  SWIG_JavaThrowException(jenv, exception_code, msg);
125}
126%}
127
128#define SWIG_exception(code, msg)\
129{ SWIG_JavaException(jenv, code, msg); return $null; }
130#endif // SWIGJAVA
131
132#ifdef SWIGOCAML
133%{
134#define OCAML_MSG_BUF_LEN 1024
135SWIGINTERN void SWIG_exception_(int code, const char *msg) {
136  char msg_buf[OCAML_MSG_BUF_LEN];
137  sprintf( msg_buf, "Exception(%d): %s\n", code, msg );
138  failwith( msg_buf );
139}
140#define SWIG_exception(a,b) SWIG_exception_((a),(b))
141%}
142#endif
143
144
145#ifdef SWIGCHICKEN
146%{
147SWIGINTERN void SWIG_exception_(int code, const char *msg) {
148  C_word *a;
149  C_word scmmsg;
150  C_word list;
151
152  a = C_alloc (C_SIZEOF_STRING (strlen (msg)) + C_SIZEOF_LIST(2));
153  scmmsg = C_string2 (&a, (char *) msg);
154  list = C_list(&a, 2, C_fix(code), scmmsg);
155  SWIG_ThrowException(list);
156}
157#define SWIG_exception(a,b) SWIG_exception_((a),(b))
158%}
159#endif
160
161#ifdef SWIGCSHARP
162%{
163SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
164  if (code == SWIG_ValueError) {
165    SWIG_CSharpExceptionArgumentCodes exception_code = SWIG_CSharpArgumentOutOfRangeException;
166    SWIG_CSharpSetPendingExceptionArgument(exception_code, msg, 0);
167  } else {
168    SWIG_CSharpExceptionCodes exception_code = SWIG_CSharpApplicationException;
169    switch(code) {
170    case SWIG_MemoryError:
171      exception_code = SWIG_CSharpOutOfMemoryException;
172      break;
173    case SWIG_IndexError:
174      exception_code = SWIG_CSharpIndexOutOfRangeException;
175      break;
176    case SWIG_DivisionByZero:
177      exception_code = SWIG_CSharpDivideByZeroException;
178      break;
179    case SWIG_IOError:
180      exception_code = SWIG_CSharpIOException;
181      break;
182    case SWIG_OverflowError:
183      exception_code = SWIG_CSharpOverflowException;
184      break;
185    case SWIG_RuntimeError:
186    case SWIG_TypeError:
187    case SWIG_SyntaxError:
188    case SWIG_SystemError:
189    case SWIG_UnknownError:
190    default:
191      exception_code = SWIG_CSharpApplicationException;
192      break;
193    }
194    SWIG_CSharpSetPendingException(exception_code, msg);
195  }
196}
197%}
198
199#define SWIG_exception(code, msg)\
200{ SWIG_CSharpException(code, msg); return $null; }
201#endif // SWIGCSHARP
202
203#ifdef SWIGLUA
204
205%{
206#define SWIG_exception(a,b)\
207{ lua_pushfstring(L,"%s:%s",#a,b);SWIG_fail; }
208%}
209
210#endif // SWIGLUA
211
212#ifdef SWIGD
213%{
214SWIGINTERN void SWIG_DThrowException(int code, const char *msg) {
215  SWIG_DExceptionCodes exception_code;
216  switch(code) {
217  case SWIG_IndexError:
218    exception_code = SWIG_DNoSuchElementException;
219    break;
220  case SWIG_IOError:
221    exception_code = SWIG_DIOException;
222    break;
223  case SWIG_ValueError:
224    exception_code = SWIG_DIllegalArgumentException;
225    break;
226  case SWIG_DivisionByZero:
227  case SWIG_MemoryError:
228  case SWIG_OverflowError:
229  case SWIG_RuntimeError:
230  case SWIG_TypeError:
231  case SWIG_SyntaxError:
232  case SWIG_SystemError:
233  case SWIG_UnknownError:
234  default:
235    exception_code = SWIG_DException;
236    break;
237  }
238  SWIG_DSetPendingException(exception_code, msg);
239}
240%}
241
242#define SWIG_exception(code, msg)\
243{ SWIG_DThrowException(code, msg); return $null; }
244#endif // SWIGD
245
246#ifdef __cplusplus
247/*
248  You can use the SWIG_CATCH_STDEXCEPT macro with the %exception
249  directive as follows:
250
251  %exception {
252    try {
253      $action
254    }
255    catch (my_except& e) {
256      ...
257    }
258    SWIG_CATCH_STDEXCEPT // catch std::exception
259    catch (...) {
260     SWIG_exception(SWIG_UnknownError, "Unknown exception");
261    }
262  }
263*/
264%{
265#include <stdexcept>
266%}
267%define SWIG_CATCH_STDEXCEPT
268  /* catching std::exception  */
269  catch (std::invalid_argument& e) {
270    SWIG_exception(SWIG_ValueError, e.what() );
271  } catch (std::domain_error& e) {
272    SWIG_exception(SWIG_ValueError, e.what() );
273  } catch (std::overflow_error& e) {
274    SWIG_exception(SWIG_OverflowError, e.what() );
275  } catch (std::out_of_range& e) {
276    SWIG_exception(SWIG_IndexError, e.what() );
277  } catch (std::length_error& e) {
278    SWIG_exception(SWIG_IndexError, e.what() );
279  } catch (std::runtime_error& e) {
280    SWIG_exception(SWIG_RuntimeError, e.what() );
281  } catch (std::exception& e) {
282    SWIG_exception(SWIG_SystemError, e.what() );
283  }
284%enddef
285%define SWIG_CATCH_UNKNOWN
286  catch (std::exception& e) {
287    SWIG_exception(SWIG_SystemError, e.what() );
288  }
289  catch (...) {
290    SWIG_exception(SWIG_UnknownError, "unknown exception");
291  }
292%enddef
293
294/* rethrow the unknown exception */
295
296#if defined(SWIGCSHARP) || defined(SWIGD)
297%typemap(throws,noblock=1, canthrow=1) (...) {
298  SWIG_exception(SWIG_RuntimeError,"unknown exception");
299}
300#else
301%typemap(throws,noblock=1) (...) {
302  SWIG_exception(SWIG_RuntimeError,"unknown exception");
303}
304#endif
305
306#endif /* __cplusplus */
307
308/* exception.i ends here */