From: Iain Dooley Date: 2005-08-29T19:33:07+09:00 Subject: Re: catching segmentation faults from Ruby ts wrote: >>>>>>"I" == Iain Dooley writes: > > > I> will crash ruby if there is no child of parent with name "widgetName". i > I> know that there is rb_funcall_protect that allows you to trap errors, > I> but the problem is that i'm not doing an rb_funcall. the functions are > I> being called from with Qt/Ruby bindings. is there a way that i can trap > I> all errors from the ruby interpreter to prevent segfaults in dynamically > I> edited code from crashing the program? > > Look at rb_eval_string_protect(), rb_protect() > in fact, the problem here is that i'm not calling the functions from within my code. what i do is create a new Qt::Object class using rb_funcall, then i look within Qt/Ruby bindings to find the underlying QObject (C++ object), then bind the slots present in this object to a dynamically loaded .ui interface file using QWidgetFactory::create(). this returns a class of object QWidget. i then create a new Qt::Widget class using rb_funcall, find the underlying object and switch the pointer to the object returned by QWidgetFactory::create(). This means that you can create .ui file in Qt Designer and then load it into an application runner and write the code that controls the GUI behaviour at runtime. it works beautifully, but because i am not doing an eval_string or a funcall to execute the code (it is all handled within Smoke and Qt/Ruby) i can't simply put rb_protect() around it. my main routine looks like this: #include #include "runner.h" #include int main( int argc, char *argv[] ) { QApplication app( argc, argv ); ruby_init(); Runner *runner = new Runner(); app.setMainWidget( runner ); runner->show(); return app.exec(); } would it be possible, do you think to have: #include #include "runner.h" #include int main( int argc, char *argv[] ) { int ret = 2; QApplication app( argc, argv ); ruby_init(); Runner *runner = new Runner(); app.setMainWidget( runner ); runner->show(); while(ret==2) ret = executeProgram(app); return ret; } int executeProgram(QApplication &app) { int ret = 0; try { ret = app.exec(); } catch(RubyException *exc) { //DISPLAY SOME ERROR MESSAGE OR MODAL DIALOG ret = 2; } return ret; } does such a RubyException exists? is there some general exception that will come floating up unhandled out of my application to meet me? cheers ian