On Friday 24 December 2010 03:32:28 Vladimir Rutsky wrote:
> 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.

If Qt isn't compiled with support for exceptions this code will cause a 
segfault.

If Qt was compiled with support for exceptions and the error occur inside the 
mainloop Qt will catch the exception and abort if it's compiled as debug or 
just rethrow the exception if it isn't.

see: src/corelib/kernel/qeventloop.cpp:202 in Qt 4.7.1 Sources.

So the situation isn't too simple :-/

> 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

-- 
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to