diff options
author | Logan Johnson <ljohnson@users.sourceforge.net> | 2003-04-29 16:08:16 +0000 |
---|---|---|
committer | Logan Johnson <ljohnson@users.sourceforge.net> | 2003-04-29 16:08:16 +0000 |
commit | 3fd12995c75720d4a759cd1edc66f2eb97425a63 (patch) | |
tree | a9b85492f85de892a77502b2611b5ef232c9dce1 /Examples/test-suite | |
parent | 9d2567b1f36ea4d981b98aa2483c458dde2df4bd (diff) | |
download | swig-3fd12995c75720d4a759cd1edc66f2eb97425a63.tar.gz |
A little more work on the Ruby support for C++ polymorphism. Exception
handling almost works...
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4745 626c5289-ae23-0410-ae9c-e8d60b6d4f22
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 + |