On Wed, Dec 22, 2010 at 10:13 PM, Hugo Parente Lima
<[email protected]> wrote:
> On Wednesday 22 December 2010 17:31:27 Николай wrote:
>> wxPython for example provides methods for changing error behavior.
>> This is requirement for professional applications.
>
> Qt and PySide too, see qInstallMsgHandler
>
> But there are two categories of errors, recoverable and unrecoverable errors,
> Qt consider those errors as unrecoverable errors, so PySide can't do nothing,
> because even if you use a custom message handler is used Qt will call abort
> after the qFatal() call as show in bug report 564 [1].
>
> [1] http://bugs.openbossa.org/show_bug.cgi?id=564
qFatal() is used in case of unrecoverable errors, yes, and after call
to qFatal()
function that called qFatal() can't continue it work. But instead of
writing error
message in out handler installed by qInstallMsgHandler() we can throw exception!
So function, that called qFatal() will be terminated and exception
will be raised.
As I see in sources at [2] this should work.
Hugo, can you modify and test your example [3] as shown below?
void myMessageOutput(QtMsgType type, const char *msg)
{
switch (type) {
...
case QtFatalMsg:
cout << "plz don't abort! " << msg << endl;
throw std::runtime_error("Fatal error!"); // Or other exception
}
}
int main()
{
qInstallMsgHandler(myMessageOutput);
// Try-catch to handle exception in qFatal.
try
{
qFatal("Hi");
}
catch( std::exception const & )
{
cout << "Exception handled" << endl;
}
cout << "I want to be executed!!!" << endl;
return 0;
}
[2] http://qt.gitorious.org/qt/qt/blobs/4.7/src/corelib/global/qglobal.cpp
[3] http://bugs.openbossa.org/attachment.cgi?id=202
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside