[Qt5-feedback] Qt5 and C++ exception
Дмитрий Б.
dmitry_bsd at inbox.ru
Mon Jun 27 10:45:48 CEST 2011
27 июня 2011, 12:25 от Arvid Ephraim Picciani <arvid.picciani at nokia.com>:
> On 06/27/2011 08:26 AM, ext Дмитрий Б. wrote:
> > Sorry guys if this question has already been discussed. Is any plans to
> > make changes in Qt-API to be able to use C++ exceptions, as in the other
> > frameworks?
> > Like this:
> >
> > QThread* thread = new QThread();
> > try
> > {
> > thread->start();
> > }
> > catch (e)
> > {
> > //Error, thread has not been created
> > }
>
>
> While this is a simple case (if you ignore abi quirks), consider this:
>
> class MyWidget: public QWidget {
> private:
> void startStuff();
> {
> thread->start();
> }
> protected:
> virtual void keyPressEvent ( QKeyEvent * event )
> {
> // if bla
> startStuff();
> }
> }
>
>
>
> What if start() throws now?
> Where do you expect your "catch" ?
> Either way, you can't unwind the eventloop. For once because that could
> contain native calls that contain no unwind information.
>
> To get reliable code, you will end up with this:
>
> void startStuff();
> {
> try {
> thread->start();
> } catch(e) {
> setError(e);
> }
> }
>
Not really. My understanding that for such situations Qt must have the default exception's handler.
THis handler for example simply displays a message in QMessageBox. This way it is implemented in VCL-Delphi or in the .NET as i know. Wrap all calls that generate exceptions does not make sense (just defeats the purpose of an exceptions).
This way if you do not want to use default handler:
virtual void keyPressEvent ( QKeyEvent * event )
{
try {
startStuff1();
startStuff2();
startStuff3();
startStuff4();
startStuff5();
} catch(e)
{
setError(e);
}
}
>
> Which is exactly what Qt does in the first place, without the boilerplate.
> _______________________________________________
> Qt5-feedback mailing list
> Qt5-feedback at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt5-feedback
More information about the Qt5-feedback
mailing list