[Qt-interest] Qt and exceptions

Stephan Rose kermos at somrek.net
Thu Dec 11 02:21:12 CET 2008


On Wed, 2008-12-10 at 23:18 +0700, Anthony Serdyukov wrote:
> Since you live in the qt world, all your code is called from the event
> loop, and there your exception is thrown. So, you can override the
> notify() method and surround the inherited call with try block.
> However, i dont think it's a good idea to catch exception on this
> level - you just cant handle it properly here. If you describe your
> exception architecture in details, the advise could be more useful.

Well, let me explain then what I'm trying to accomplish.

I have my own class for making sql queries to my database that
internally uses a QSqlQuery object and checks the results of exec(),
prepare(), etc. as appropriate.

Generally speaking, these calls should always succeed. If they don't
it's either due to a SQL syntax error that somehow snuck in or there is
some major discrepancy in the data that causes a key relationship to
fail. Either way, such an event potentially puts the remainder of
whatever the application may need to do in an undefined state.

So for that reason I'm having it throw an exception so that any and all
further code execution stops, an error report can be generated and the
app restarted.

If QT provides a better mechanism for something like this that I have
overlooked then I'd be more than happy to use it.

Thanks,

Stephan





More information about the Qt-interest-old mailing list