dynamic library loading and c++ excpetion part 2 ;)

Vianney Lecroart lecroart@nevrax.com
Wed Jan 24 01:02:00 GMT 2001


in fact, my last example was wrong and worked :)
my problem is when I want to throw an exception in the lib and catch it
outside the lib in the main.
when in throw the exception in the main it works fine, but when I throw it
in the lib, it crashs :(

the new example:
--------- app.cpp --------
#include <dlfcn.h>
int main(int argc, char **argv) {
  void* lib = dlopen("./liblib.so", RTLD_NOW);
  if (!lib) {
    printf("DLFCN error: %s\n", dlerror());
    return 1;
  }
  void* f = dlsym(lib, "f");
  if (!f) {
    printf("DLFCN error: %s\n", dlerror());
    return 2;
  }
  try {
      /* throw "foobar"; */
      ((void(*)(void))f)();
    } catch (...) {
      printf("exception catched\n");
    }
  dlclose(lib);
  return 0;
}
----------- lib.cpp ---------------
void fnct() {
  throw "foobar";
}

extern "C" {
void f(void) {
  fnct();
}
}
---------------------------------------

--
Vianney Lecroart
---
lead programmer / nevrax.com
icq#: 6870415
homepage: http://ace.planet-d.net
www.geek.com: GCS/E d- s+++: a-- C+++$ UL++ P- L+++>+$ E+>- W++ N+ o? K-
w++$ O- M- V- PS- PE? Y PGP t 5? X+ R- tv++ b- DI D+ G e++ h+ r-- y?






More information about the Gcc mailing list