C++ Exception not caught (Qt Project)

803 views Asked by At

My problem is the following:

There is a shared library called Interface.so which is based on ICE (Internet Communication Engine) and something like a wrapper for frequently recurring tasks. One of these tasks is to register for a topic (similar to an id). In case, this topic does not exist already, ICE throws an exception called NoSuchTopic.

If I use Interface.so with a stand-alone Qt application it is possible for me to catch the NoSuchTopic exception and create the topic in the catch block (the catch block resides in Interface.so). But I want to do the same in a plugin for a flight simulator, which is itself a shared object - and here the exception is not caught by the previous mentioned catch block in Interface.so. Instead, the flight simulator crashes stating

 terminate called after throwing an instance of 'IceStorm::NoSuchTopic' 

nm -C -D says that 'IceStorm::NoSuchTopic' is undefined in Interface.so. Is this ok? Or should there be a reference where to find the definition? I already added the entry for libIceStorm.so (libs += -lIceStorm) where IceStorm::NoSuchTopic is defined (according to nm) but that does not change anything!

I also tried '-Wl,-E' but I don't know if I set this option correctly in Qt Creator. Would this help at all?

I would be grateful for every hint.

2

There are 2 answers

1
Silas Parker On

When I've had this problem before it is usually due to type information not being available.

You can often catch the exception with a try {} catch (...) {} block as that catches exceptions even when type info is missing, but it isn't particularly useful!

This is often a problem if the shared library has had symbols hidden, see the GCC Visibility article, especially the "Problems with C++ exceptions (please read!)" section.

This question recommends the use of the extra flags.

Sometimes a clean-rebuild will fix things if something is built against an old version of the library. If a clean-rebuild fixes the problem, check your build script is correct.

0
Rachael On

Sounds like the previous version used the "no-exceptions" flag when building from source. It adds a lot of time to the build so a lot of people leave it off.