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

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -