[Qt-interest] Qt and exceptions
Peter Hackett
peter.hackett at icmanage.com
Wed Dec 10 19:48:30 CET 2008
I agree that this isn't a good place to handle it. However, if you do
get to here and it hasn't
been handled, it's better to handle it yourself than let Qt do it (which
provides no info at all.)
Here's my code:
bool
IqtApplication::notify(QObject* receiverIn,QEvent* eventIn)
{
try
{
return QApplication::notify(receiverIn,eventIn);
} catch ( std::exception& e ) {
std::cerr << "IqtApplication::notify: std exception "
<< e.what() << std::endl;
} catch ( oaException e ) {
std::cerr << "IqtApplication::notify: unhandled oa exception:\n"
<< e.getMsg() << std::endl;
} catch ( ... ) {
std::cerr << "IqtApplication::notify: unknown exception" <<
std::endl;
throw;
}
return false;
}
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.
>
> 2008/12/10, Stephan Rose <kermos at somrek.net>:
>
>> On Wed, 2008-12-10 at 20:40 +0700, Anthony Serdyukov wrote:
>>
>>> You need to override notify() method of QCoreApplication, as far as i
>>> remember.
>>>
>> I looked at that but that just seems to deal with events, there is no
>> mention about exceptions in the docs. I also don't see anything in the
>> function that would help me allow dealing with exceptions.
>>
>> Hmm, maybe I need to see if I can find a better way to do this somehow.
>>
>> Thanks,
>>
>> Stephan
>>
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
>
>
>
More information about the Qt-interest-old
mailing list