This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Throw/Catch not working in SO?
- From: "Charles Y. Kim" <ckim at telcontar dot com>
- To: "'Janis Johnson'" <janis187 at us dot ibm dot com>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Mon, 14 Oct 2002 17:21:28 -0700
- Subject: RE: Throw/Catch not working in SO?
- Reply-to: <ckim at telcontar dot com>
Good points Janis. Here are a few answers.
I've tried building the SO with the -fPIC flag. The shared object is being
built with "g++ -shared".
Do I have to do something special when I open up the SO with dlopen? I've
tried using dlopen("...", RTLD_NOW/LAZY || RTLD_GLOBAL) and those don't seem
to do anything either. I've added -Wl,-E to the link line as well, but to
no avail.
This works in other platforms... I'm just stumped as to why it might not
work with Linux. Also, this is a multithreaded app, and the actual SO is
FAR more complex than the code sample below.
I can see that throw is being called because I've checked out the stack
trace in GDB.
- Charles
-----Original Message-----
From: Janis Johnson [mailto:janis187@us.ibm.com]
Sent: Monday, October 14, 2002 5:16 PM
To: Charles Y. Kim
Cc: gcc@gcc.gnu.org
Subject: Re: Throw/Catch not working in SO?
On Mon, Oct 14, 2002 at 03:37:40PM -0700, Charles Y. Kim wrote:
> Hi all,
>
> I'm using some exception handling in a shared object, and while the
> throw()/catch() works in both Windows and FreeBSD (using GCC 2.96), in
Linux
> (GCC 3.02 --enable-shared --enable-threads=posix) the throw is executed,
and
> the catch never happens.
>
> For example... let's say I have the following code in the shared object...
>
> void error() {
> throw(1);
> }
>
> void error2() {
> error();
> }
>
> void function() {
> try {
> if (blah)
> error2();
> }
> catch(...) {
> printf("exception caught");
> }
> }
>
> I know that error2() is being called and the exception is being thrown...
> but it's not being caught at all.
>
> Does anyone have ANY ideas?
It works fine for me with GCC 3.0.4 on i686-pc-linux-gnu, but I
can't tell what I might have done differently.
Your code fragment isn't complete (it can't be compiled without
additional code added), and you don't say how you built your shared
object or how you know that error2 was called. If you provide a
complete example, someone might be able to help.
Janis