PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 131 lines | 104 code | 21 blank | 6 comment | 0 complexity | 1b64eb4f935120983a8af0af0889b5c3 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module exception_order
  2. %warnfilter(SWIGWARN_RUBY_WRONG_NAME);
  3. #if defined(SWIGGO) && defined(SWIGGO_GCCGO)
  4. %{
  5. #ifdef __GNUC__
  6. #include <cxxabi.h>
  7. #endif
  8. %}
  9. #endif
  10. %include "exception.i"
  11. %{
  12. #if defined(_MSC_VER)
  13. #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  14. #endif
  15. %}
  16. /*
  17. last resource, catch everything but don't override
  18. user's throw declarations.
  19. */
  20. #if defined(SWIGUTL)
  21. %exception {
  22. try {
  23. $action
  24. } catch(...) {
  25. SWIG_exception_fail(SWIG_RuntimeError,"postcatch unknown");
  26. }
  27. }
  28. #elif defined(SWIGGO) && defined(SWIGGO_GCCGO)
  29. %exception %{
  30. try {
  31. $action
  32. #ifdef __GNUC__
  33. } catch (__cxxabiv1::__foreign_exception&) {
  34. throw;
  35. #endif
  36. } catch(...) {
  37. SWIG_exception(SWIG_RuntimeError,"postcatch unknown");
  38. }
  39. %}
  40. #else
  41. %exception {
  42. try {
  43. $action
  44. } catch(...) {
  45. SWIG_exception(SWIG_RuntimeError,"postcatch unknown");
  46. }
  47. }
  48. #endif
  49. %catches(E1,E2*,ET<int>,ET<double>,...) A::barfoo(int i);
  50. %allowexception efoovar;
  51. %allowexception A::efoovar;
  52. %inline %{
  53. int efoovar;
  54. int foovar;
  55. const int cfoovar = 1;
  56. struct E1
  57. {
  58. };
  59. struct E2
  60. {
  61. };
  62. struct E3
  63. {
  64. };
  65. template <class T>
  66. struct ET
  67. {
  68. };
  69. struct A
  70. {
  71. static int sfoovar;
  72. static const int CSFOOVAR = 1;
  73. int foovar;
  74. int efoovar;
  75. /* caught by the user's throw definition */
  76. int foo() throw(E1)
  77. {
  78. throw E1();
  79. return 0;
  80. }
  81. int bar() throw(E2)
  82. {
  83. throw E2();
  84. return 0;
  85. }
  86. /* caught by %postexception */
  87. int foobar()
  88. {
  89. throw E3();
  90. return 0;
  91. }
  92. int barfoo(int i)
  93. {
  94. if (i == 1) {
  95. throw E1();
  96. } else if (i == 2) {
  97. static E2 *ep = new E2();
  98. throw ep;
  99. } else if (i == 3) {
  100. throw ET<int>();
  101. } else {
  102. throw ET<double>();
  103. }
  104. return 0;
  105. }
  106. };
  107. int A::sfoovar = 1;
  108. %}
  109. %template(ET_i) ET<int>;
  110. %template(ET_d) ET<double>;