c++ - catching an exception in a loaded shared library -
is catching exception thrown in loaded shared library portable? i've noticed works dlfcn.h, wonder if behaviour in general expected, example when using loadlibrary on windows instead?
example code:
main.cpp:
#include <stdexcept> #include <cstdio> #include <dlfcn.h> typedef void(*dummy_t)(); int main() { dummy_t f; void* handle; handle = dlopen("module.so", rtld_lazy); f = (dummy_t)dlsym(handle, "modulemain"); try { f(); } catch(std::runtime_error& e) { fprintf(stderr, "caught exception: %s\n", e.what()); } dlclose(handle); } module.cpp:
#include <stdexcept> extern "c" void modulemain() { throw std::runtime_error("some terrible error occured"); }
yes, should work fine under windows.
Comments
Post a Comment