public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Throw/Catch not working in SO?
@ 2002-10-14 17:36 Charles Y. Kim
  2002-10-14 18:38 ` Janis Johnson
  0 siblings, 1 reply; 5+ messages in thread
From: Charles Y. Kim @ 2002-10-14 17:36 UTC (permalink / raw)
  To: gcc

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?

Thanks.

- Charles


^ permalink raw reply	[flat|nested] 5+ messages in thread
* RE: Throw/Catch not working in SO?
@ 2002-10-15  2:45 Rob
  0 siblings, 0 replies; 5+ messages in thread
From: Rob @ 2002-10-15  2:45 UTC (permalink / raw)
  To: ckim; +Cc: gcc

This might be a manifestation of a problem involving different versions of the c++ support library, which includes functions used for internal run-time type identification and exception handling. If your main app is linked against one version of the support library and your shared library is linked against another, then Weird Stuff can happen.
Reported manifestations include exceptions not being caught, or SEGVs during the initial throw.

The simple solution is to just make sure the app and the lib are linked against the same version of the library (and, presumably, are built with the same C++ compiler). Unfortunately, not all of us have that luxury.

It seems to me that statically linking the support library into the shared object and then privatizing all the symbols should avoid these kinds of conflicts (and should prevent C++ ABI fragility, if the shared lib uses only a C interface), but I have been unable to get this to work. I'm still trying to figure out just what ld.so is doing to screw things up...

Hope this helps.

-rob

> -----Original Message-----
> From: Charles Y. Kim [mailto:ckim@telcontar.com]
> Sent: 14 October 2002 23:38
> To: gcc@gcc.gnu.org
> Subject: Throw/Catch not working in SO?
> 
> 
> 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?
> 
> Thanks.
> 
> - Charles
> 
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-10-15  8:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-14 17:36 Throw/Catch not working in SO? Charles Y. Kim
2002-10-14 18:38 ` Janis Johnson
2002-10-14 18:39   ` Charles Y. Kim
2002-10-14 21:14     ` Fergus Henderson
2002-10-15  2:45 Rob

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).