Catching exceptions accross shared libraries

N

Nindi

Hi

I have a scenario with exceptions that I cannot explain.

I have an exception class 'MyException' derived from 'std::exception'

There are two libraries 'plugin' and 'framework' linked together by
loading at runtime.

The issue is that an exception of type 'MyException' is being thrown in
'plugin' and caught in 'framework', but some throws get caught by the
'MyExeption' handler and some some throws get caught by the
'std::exception' handler, in the same try-catch block.

Has anybody got any ideas what could possibly cause this to happen ?

I only get this problem when building with gcc on Linux, I do not have
this problem with msvc

Cheers
N
 
G

Gianni Mariani

Nindi said:
Hi

I have a scenario with exceptions that I cannot explain.

I have an exception class 'MyException' derived from 'std::exception'

There are two libraries 'plugin' and 'framework' linked together by
loading at runtime.

The issue is that an exception of type 'MyException' is being thrown in
'plugin' and caught in 'framework', but some throws get caught by the
'MyExeption' handler and some some throws get caught by the
'std::exception' handler, in the same try-catch block.

Has anybody got any ideas what could possibly cause this to happen ?

I only get this problem when building with gcc on Linux, I do not have
this problem with msvc


The only real way of helping you is to show is the code. It could
possibly be a bug in gcc. What version of gcc are you using and are
framework and plugin build with the same compiler?
 
N

Nindi

Gianni said:
The only real way of helping you is to show is the code. It could
possibly be a bug in gcc. What version of gcc are you using and are
framework and plugin build with the same compiler?

I would like to show code .. but I don't think I could rip that part of
code out an reproduce the errors. I am also looking at
http://gcc.gnu.org/wiki/Visibility , I 'think' my problem is detailed
there. I am using gcc 4.1
 
N

Nindi

Nindi said:
I would like to show code .. but I don't think I could rip that part of
code out an reproduce the errors. I am also looking at
http://gcc.gnu.org/wiki/Visibility , I 'think' my problem is detailed
there. I am using gcc 4.1



OK .. I fixed it , but I still don't know what was wrong. The header
file for 'MyException' contained the class implementation as well as
the class definition, This header file was being included in both
'plugin' and 'framework' .
I moved the implementation out into a seperate library and linked it
in.
Now its the 'MyException' Handler and not the ''std::exception'
handler that catches 'MyException' .
 
G

Gianni Mariani

Nindi wrote:
....
OK .. I fixed it , but I still don't know what was wrong. The header
file for 'MyException' contained the class implementation as well as
the class definition, This header file was being included in both
'plugin' and 'framework' .
I moved the implementation out into a seperate library and linked it
in.
Now its the 'MyException' Handler and not the ''std::exception'
handler that catches 'MyException' .

Yes. That might help. The issue is that the compiler generates
multiple versions of the "MyException" constructor (and possibly other
things) if the definition is in the header. By placing it in the
"framework" library you're limiting it to 1 compiled copy and hence
forcing the linker to use the version specified. I still think it's a
gcc bug though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top