This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: dynamic library loading and c++ excpetion part 2 ;)
- To: Vianney Lecroart <lecroart at nevrax dot com>
- Subject: Re: dynamic library loading and c++ excpetion part 2 ;)
- From: "H . J . Lu" <hjl at valinux dot com>
- Date: Wed, 24 Jan 2001 10:13:43 -0800
- Cc: gcc at gcc dot gnu dot org
- References: <002301c085e4$7b63f540$0901a8c0@vianneyl>
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.