[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: C++ exceptions
From:       Thiago Macieira <thiago () kde ! org>
Date:       2005-12-07 12:54:02
Message-ID: 200512071054.03225.thiago () kde ! org
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


Volker Lukas wrote:
>Thiago Macieira wrote:
>> [...]
>>
>> Allowing the exception to reach the Qt signal/slot mechanism is bound
>> to fail and, quite possibly, core dump.
>
>This does not seem to be true. There is no place in the Qt documentation
>which forbids this (or at least no prominent one), and Trolltech
> actually treats problems which arise in the situation you described as
> bugs. So while letting exceptions leave a slot or event-handler might
> not be recommended practice, Qt is at least intended to work correct in
> that case.

That's true if the library was built with exceptions enabled.

Since it doesn't use exceptions for itself (except as a result of operator 
new), it can be built with -fno-exceptions. And in that case, letting 
exceptions propagate into the library will probably cause core dumps.

What I don't know is if it's recommended to use -fno-exceptions. The Qt 
configure script doesn't set it on by default, but it does have the 
option:
    -no-exceptions ..... Disable exceptions on platforms that support it.
 *  -exceptions ........ Enable exceptions on platforms that support it.

So, my recommendation stays: do not let exceptions propagate to inside the 
Qt libraries and, even more so, the KDE libraries. Doing so could cause 
problems for you later.

>Qt does use exceptions. It might not contain many throw-statements, but
> it uses the throwing forms of "new", and it lets exceptions (from new
> or from user code) propagate out of the library.

True. And I think all those "new" that allocate memory that is potentially 
large should either be in a try/catch block or use new(nothrow) so as to 
catch bad allocations. One such case is demarshalling a QDataStream.

Those normal "new", allocating memory for objects, don't need to check for 
the result or exception being thrown. If that happens, the user is in 
serious problem already. That's the consensus we've reached in this list 
and in kde-core-devel a few years ago.

Does anyone know if the stack unwinder requires memory to be allocated in 
order to run?
-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

2. Tó cennan his weorc gearu, ymbe se circolwyrde, wearð se cægbord and se 
leohtspeccabord, and þa mýs cómon lator. On þone dæg, he hine reste.

[Attachment #5 (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic