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]

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


On Wed, Jan 24, 2001 at 10:03:12AM +0100, Vianney Lecroart wrote:
> 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;
> }

It is a very subtle problem.

# gcc app.cpp -ldl -rdynamic
# ./a.out
exception catched


H.J.

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