PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Swig | 79 lines | 70 code | 9 blank | 0 comment | 0 complexity | 7084c3c53e65902bc61e31a6717ab30a MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. %module throw_exception
  2. %{
  3. #if defined(_MSC_VER)
  4. #pragma warning(disable: 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
  5. #endif
  6. %}
  7. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Namespace::enum1;
  8. %warnfilter(SWIGWARN_RUBY_WRONG_NAME) Namespace::enum2;
  9. #ifdef SWIGPHP
  10. %warnfilter(SWIGWARN_PARSE_KEYWORD) Namespace;
  11. #endif
  12. // Tests SWIG's automatic exception mechanism
  13. %inline %{
  14. class Error {
  15. };
  16. void test_is_Error(Error *r) {}
  17. namespace Namespace {
  18. typedef Error ErrorTypedef;
  19. typedef const Error& ErrorRef;
  20. typedef const Error* ErrorPtr;
  21. typedef int IntArray[10];
  22. enum EnumTest { enum1, enum2 };
  23. }
  24. class Foo {
  25. public:
  26. void test_int() throw(int) {
  27. throw 37;
  28. }
  29. void test_msg() throw(const char *) {
  30. throw "Dead";
  31. }
  32. void test_cls() throw(Error) {
  33. throw Error();
  34. }
  35. void test_cls_ptr() throw(Error *) {
  36. static Error StaticError;
  37. throw &StaticError;
  38. }
  39. void test_cls_ref() throw(Error &) {
  40. static Error StaticError;
  41. throw StaticError;
  42. }
  43. void test_cls_td() throw(Namespace::ErrorTypedef) {
  44. throw Error();
  45. }
  46. void test_cls_ptr_td() throw(Namespace::ErrorPtr) {
  47. static Error StaticError;
  48. throw &StaticError;
  49. }
  50. void test_cls_ref_td() throw(Namespace::ErrorRef) {
  51. static Error StaticError;
  52. throw StaticError;
  53. }
  54. void test_array() throw(Namespace::IntArray) {
  55. static Namespace::IntArray array;
  56. for (int i=0; i<10; i++) {
  57. array[i] = i;
  58. }
  59. throw array;
  60. }
  61. void test_enum() throw(Namespace::EnumTest) {
  62. throw Namespace::enum2;
  63. }
  64. void test_multi(int x) throw(int, const char *, Error) {
  65. if (x == 1) throw 37;
  66. if (x == 2) throw "Dead";
  67. if (x == 3) throw Error();
  68. }
  69. };
  70. %}