![]() |
|
#1
|
|||
|
|||
Shared Libraries with qmake and Exception HandlingHello to everyone.
I have a big problem with exceptions in a shared library I created myself. Here's the scenario: I wrote a few classes to create UDP servers and clients which are able to send and receive messages. In the functions of this classes I integrated an exception handling, for example: CPP / C++ / C Code:
In case receiving of data failed, it is checked whether a socket has been initialized before or not. If no socket has been initialized, an exception is thrown. This works fine, since a binary has been created using this sourcefiles. A problem occurs, when I want it to make a shared library using qmake. Creating the shared library works fine and I am able to use it in another project, like in the following example: CPP / C++ / C Code:
The object mBrdNetAccess was created before and a socket was opened, so in this case everything works fine while receiving data. Now I tried to throw an exception like in the upper sourcecode by not initializing a socket before. The exception is caught in a main: CPP / C++ / C Code:
ConnException should catch the exceptions that are thrown by the shared library. CHAException catches the exceptions thrown by the source code which uses the shared library. The problem is, that when the exception like in the first example is thrown, then I always get a message like this: Code:
I just want the exception to get caught by the catch handler in the main. I cannot find a reason for this, the only thing I found out by searching the internet is, that it seems so be a compiler problem. For creating the library I used qmake, here is the project file: Code:
Maybe someone of u can help me with this. I am using Ubuntu, kernel version 2.6.20-16-generic and gcc version 4.1.2. |
|||
|
#2
|
|||
|
|||
Re: Shared Libraries with qmake and Exception HandlingBy default, Qt builds for Debian and its variants (including Ubuntu) turns exceptions off. (-fno-exceptions) If you want to enable them, you'll need to rebuild Qt with exceptions enabled.
It is entirely possible for you to have two Qt installations on your machine, one with and one without exceptions, but it does require more "management" from you to ensure that you are using the right set of libraries both at link-time and at run-time. :davis: |
|
#3
|
|||
|
|||
Re: Shared Libraries with qmake and Exception HandlingHello davis and thanks for the reply.
I followed your advice and reinstalled qt (4.3.3) by using the source, not the package manager. So I was able to enable the exception option (besides, I think the same option u can set in the project file by using CONFIG += exception). I got the same results as before. At the moment I don't think it is a problem with the library but a problem with the exception handling and that what I wrote is not thread safe. I tried to catch the exception the function in the library throws directly in the source file: CPP / C++ / C Code:
This seems to work fine. So I think, the problem is, catching the exception in the main does not work, because it is another thread. Does anyone have an idea about that? |
|
#4
|
|||
|
|||
Re: Shared Libraries with qmake and Exception HandlingTry to reproduce the problem outside of Qt. Try to write something very, very simple using a benign "shared library" that you write with only one function that throws an exception. Build it and test it to see if it exhibits the same behavior. Without all of your code, I can't really help you debug it...and I probably don't want all of it either!
If you have a dead simple Linux console app that does exhibit the problem you're mentioning, I can take a look at it (and so can others here, too) and let you know what you can do to fix it. :davis: |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The