diff options
Diffstat (limited to 'Examples/test-suite')
-rw-r--r-- | Examples/test-suite/director_exception.i | 15 | ||||
-rw-r--r-- | Examples/test-suite/ruby/director_exception_runme.rb | 42 |
2 files changed, 57 insertions, 0 deletions
diff --git a/Examples/test-suite/director_exception.i b/Examples/test-suite/director_exception.i index e452e5adc..43a7f68ea 100644 --- a/Examples/test-suite/director_exception.i +++ b/Examples/test-suite/director_exception.i @@ -31,6 +31,7 @@ class SWIG_DIRECTOR_METHOD_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION {}; %include "exception.i" %include "std_string.i" +#ifdef SWIGPYTHON %feature("director:except") { if ($error != NULL) { @@ -43,6 +44,20 @@ class SWIG_DIRECTOR_METHOD_EXCEPTION: public SWIG_DIRECTOR_EXCEPTION {}; catch (SWIG_DIRECTOR_EXCEPTION &e) { SWIG_fail; } } +#endif + +#ifdef SWIGRUBY + +%feature("director:except") { + throw SWIG_DIRECTOR_METHOD_EXCEPTION(); +} + +%exception { + try { $action } + catch (SWIG_DIRECTOR_EXCEPTION &e) { rb_raise(e.getType(), e.getMessage()); } +} + +#endif %feature("director") Foo; diff --git a/Examples/test-suite/ruby/director_exception_runme.rb b/Examples/test-suite/ruby/director_exception_runme.rb new file mode 100644 index 000000000..0d91a4f2e --- /dev/null +++ b/Examples/test-suite/ruby/director_exception_runme.rb @@ -0,0 +1,42 @@ +require 'director_exception' + +include Director_exception + +class MyFoo < Foo + def ping + raise NotImplementedError, "MyFoo::ping() EXCEPTION" + end +end + +class MyFoo2 < Foo + def ping + nil # error: should return a string + end +end + +ok = false + +a = MyFoo.new +b = launder(a) + +begin + b.pong +rescue NotImplementedError + ok = true +end + +raise RuntimeError unless ok + +ok = false + +a = MyFoo2.new +b = launder(a) + +begin + b.pong +rescue TypeError + ok = true +end + +raise RuntimeError unless ok + |