Hi!
I still have some problems with embedding Ruby in an application.
SWIG uses rb_rescue2() to invoke methods. Now I would like to throw
a C++ exception, if Ruby raises any exception. SWIG puts this throw
statement in the rescue_func function passed to rb_rescue2().
But for some reason, I can't catch this exception from my C++ application.
(See the small sample code at the end... the exception never gets caught. It
somehow gets lost in rb_rescue())
Is it simply not possible to "transform" a Ruby exception into a C++
exception using rb_rescue2()? Will I have to rewrite SWIG to use rb_protect()?
bye,
Tobias
#include <ruby.h>
#include <iostream>
VALUE begin_func(VALUE begin_func_args)
{
return rb_funcall(begin_func_args, rb_intern("givemeanerror"), 0, NULL);
}
VALUE rescue_func(VALUE rescue_func_args, VALUE error_info)
{
cerr << "throwing exception" << endl;
throw "exception";
}
int main()
{
ruby_init();
try {
rb_rescue((VALUE(*)(ANYARGS)) begin_func, Qnil,
(VALUE(*)(ANYARGS)) rescue_func, Qnil);
}
catch (...) {
cerr << "exception caught" << endl ;
}
ruby_finalize();
return 0;
}