libpcl and c++ exceptions
てきとーなテストコード書いて問題なかった。
somari(Gentoo Linux / Linux 2.6 x86_64)でテスト。あとでpersianのwin32環境でもテストすること。
実行結果:
ObjHandleTester C-tor :continuable_func entering continuable_func() returned from coroutine ObjHandleTester C-tor :inside try ObjHandleTester C-tor :throwing_func ObjHandleTester D-tor :throwing_func ObjHandleTester D-tor :inside try caught exception exiting continuable_func() ObjHandleTester D-tor :continuable_func returned from coroutine : 2nd time exiting...
ソース:
// libpcl exception handling test #include <iostream> #include <string> #include <pcl.h> class ObjHandleTester { public: ObjHandleTester(const std::string& id) : m_id(id) { std::cout << "ObjHandleTester C-tor :" << id << std::endl; } ~ObjHandleTester() { std::cout << "ObjHandleTester D-tor :" << m_id << std::endl; } std::string m_id; }; class FException {}; void throwing_func() { ObjHandleTester aaa("throwing_func"); throw FException(); } void continuable_func(void*) { ObjHandleTester bbb("continuable_func"); std::cout << "entering continuable_func()" << std::endl; try { co_resume(); } catch(FException &e) { std::cout << "should not come here!!!" << std::endl; } try { ObjHandleTester ccc("inside try"); throwing_func(); } catch(FException &e) { std::cout << "caught exception" << std::endl; } std::cout << "exiting continuable_func()" << std::endl; } int main() { coroutine_t co; co = co_create(&continuable_func, NULL, NULL, 32 * 1024); co_call(co); std::cout << "returned from coroutine" << std::endl; try { // try modifying exception stack throw FException(); } catch(FException &) {} try { co_call(co); std::cout << "returned from coroutine : 2nd time" << std::endl; std::cout << "exiting..." << std::endl; } catch(FException&) {} return 0; }