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@4745 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c6f231f597
commit
184da7430f
5 changed files with 161 additions and 59 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
42
SWIG/Examples/test-suite/ruby/director_exception_runme.rb
Normal file
42
SWIG/Examples/test-suite/ruby/director_exception_runme.rb
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue