I know, this question has been asked quite some times, however I can't find a solution for my problem.
I have the following situation:
A
/ \
/ \
B <-- C
EException
At some point C throws an instance of EException
:
void doSometing() {
throw EException("test-message");
}
in B
I would like to catch this exception:
try {
doSomething();
} catch (const EException& ex) {
// Not reached
} catch (...) {
// Not reached
}
but as mentioned in the code, neither one of the catch clauses get called. Instead the thread, this code is executed in, gets aborted.
I tried the following things:
EException
is set to "default" when compiling AEException
header file contains declarations only-fvisibility=hidden
in A, B and C-E
in CUsing nm
I get for A
:
0000000000066260 T EException::EException(QString const&)
0000000000066306 T EException::EException(EException const&)
00000000000661d0 T EException::EException()
0000000000066260 T EException::EException(QString const&)
0000000000066306 T EException::EException(EException const&)
00000000000661d0 T EException::EException()
00000000000664de T EException::~EException()
000000000006641e T EException::~EException()
000000000006641e T EException::~EException()
00000000000663b6 T EException::operator=(EException const&)
<...>
000000000028de40 V typeinfo for EException
000000000028dd80 V typeinfo for EException*
000000000007342b V typeinfo name for EException
0000000000072ab7 V typeinfo name for EException*
000000000028de00 V vtable for EException
for B
:
U EException::EException(QString const&)
U EException::~EException()
<...>
0000000000726f60 V typeinfo for EException
and for C
:
U EException::EException(QString const&)
U EException::~EException()
<...>
U typeinfo for EException
Could the problem be, that B
uses its own typeinfo of EException
, while C
uses the one provided by A
? How would I fix this?
My environment:
Thank you for your help!
I had similar problems with gcc < 4.5 with RTTI symbols used across shared library boundaries, but not with gcc 4.6. However, you might still find the following information useful.
As already mentioned, the vtable (containing an entry to the typeinfo object) for EException
seems to be duplicated in some translation units which was definitely a problem with gcc < 4.5 (well, it is an issue of libsupc++, as far as I know, not merging the type_info objects). Anchoring the vtable of EException
by defining a virtual out-of-line destructor (it must be the first virtual function declaration in the header) in A
did the trick for me.
Posting the complete header file for EException
might also be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With