PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/Lib/exception.i

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