views:

282

answers:

1

I am having an application heavily based on QT and on a lot of third party libs. THese happen to throw some exceptions in several cases. In a native Qt App this causes the application to abort or terminate. Often the main data model is still intact as I am keeping it in pure Qt with no external data. So I am thinking that I could also just recover by telling the user that there has occured an error in this an that process and he should save now or even decide to continue working on the main model. Currently the program jsut silently exits without even telling a story.

Please help.

+3  A: 

As stated in the Qt documentation here, Qt is currently not fully exception safe. The "Recovering from exceptions" section on that page describes the only thing which you can do in a Qt application when an exception is thrown - clean up and exit the app.

Given that you are using third party libraries which do throw exceptions, you need to catch these at the boundary between the external library and the Qt code, and handle them there - as stated in Caleb's comment. If the error must be propagated into the Qt application, this must be done either by returning an error code (if possible), or by posting an event.

Gareth Stockwell
thank you for your comment, I have remimplented QApplication::notify() and catch everything there. This is pretty good as the app just does not simply exit but allows the user to save his data at least now. I have tested this by throwing exceptions std::bad_alloc and the like from my code. In addition, I am calling the third party lib's code from inside a try {} catch(...), but nothing happens, the app just crashes.
Georg