This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


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?





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]