PDA

View Full Version : Reimplementing QApplication::notify()



Doug Broadwell
9th June 2007, 17:36
(C++ newbe also) I have code in my event handlers that throw errors. I would like to reimplement QApplication::notify() to be able to catch any thrown errors that I don't explicitly throw to deal with somewhat more gracefully than aborting the program.

Does anyone have an example code to do this?

Thanks,
Doug Broadwell

Doug Broadwell
10th June 2007, 03:16
I'm surprised that no one has done this (or has another elegant solution) to handle thrown errors.

Or maybe my question is just lame and I don't realize it. Possible.

Doug

marcel
10th June 2007, 06:03
Why don't you just try doing it and see if it works...
From what event handlers do you throw exceptions? I am asking because notify() might not be the best place to catch exceptions. Better try with event():


bool SomeObject::event( QEvent* e )
{
bool result = false;

try
{
result = QObject::event( e );
} catch( SomeException exception )
{
....
}

return result;
}



Regards

Doug Broadwell
19th June 2007, 01:02
The event handlers are gui input elements - whenever one is accessed a lot of non-gui processing goes on - I have added a lot of error catching code for things "that should never happen" (but sometimes do as the application is being debugged), so I only catch the exceptions that "could" occur, and I want to have a top level exception handler to deal with the pathalogical ones. The error I get as the Qt runtime aborts is that "exceptions are not allowed in event handlers, reimplement QApplication:notify() to catch them".

I'm such a Qt and C++ newbe that I'm not sure how to do this and I figured that it was probably something that was often done by other people, that's why I asked.

Thanks,
Doug Broadwell

wysota
19th June 2007, 01:12
(C++ newbe also) I have code in my event handlers that throw errors. I would like to reimplement QApplication::notify() to be able to catch any thrown errors that I don't explicitly throw to deal with somewhat more gracefully than aborting the program.

Does anyone have an example code to do this?

Thanks,
Doug Broadwell

Isn't this a double thread? I remember someone asked about the exact same thing about a week ago...

Doug Broadwell
21st June 2007, 21:41
It was probably this same thread, I just took a while to respond last time.

Doug