[Qt5-feedback] Qt5 and C++ exception

Craig.Scott at csiro.au Craig.Scott at csiro.au
Tue Jun 28 00:29:52 CEST 2011


On Windows with visual studio compilers (haven't tested the 2010 version, but I believe the previous versions all have this issue), the standard std::exception class is not exported, so you can't even catch exceptions by this common base class across shared library boundaries - which means Qt itself could not throw any exception class derived from std::exception and allow user code to catch it by a const std::exception& reference, for example. If you've never encountered this before, it can drive you nuts the first time you find yourself scratching your head wondering why your code is not catching an exception you are 100% sure it should be catching!

Yes, Qt could define its own exception hierarchy to work around this limitation, but I'm in agreement with the various other people who have already responded with other valid reasons not to use exceptions in Qt's API.


On 28/06/2011, at 1:15 AM, <joao.abecasis at nokia.com> <joao.abecasis at nokia.com> wrote:

> Even gcc / Linux has some issues with exceptions across shared library boundaries. They're related to symbol visibility and how exceptions classes are exported in each library in the stack trace. Such issues are also no fun tracking down...
> 
> Cheers,
> 
> 
> João
> ________________________________________
> From: qt5-feedback-bounces+joao.abecasis=nokia.com at qt.nokia.com [qt5-feedback-bounces+joao.abecasis=nokia.com at qt.nokia.com] On Behalf Of ext Ivan Cukic [ivan.cukic at kde.org]
> Sent: 27 June 2011 10:22
> To: qt5-feedback at qt.nokia.com
> Subject: Re: [Qt5-feedback] Qt5 and C++ exception
> 
> On Monday, 27. June 2011. 12.11.21 Дмитрий Б. wrote:
>> I very much respect your opinion, but there is a part of community who
>> believe that exceptions is very important. In addition it is one of the
>> standard of the C++ which Qt does not support on the API level and it
>> is a standard for any object-oriented library at all.
> 
> While I generally like the concept of exceptions, those are quite tricky
> with c++.
> 
> As Lars pointed out, dynamic libs and exceptions don't really mix well on
> some platforms (for example, mixing msvc and gcc compiled exception-
> enabled code will result in a unique kind of hell :) )
> 
> I'm not aware of non-windows os problems, but even if so, a large portion
> of Qt users are on that platform.

--
Dr Craig Scott
Computational Software Engineering Team Leader, CSIRO (CMIS)
Melbourne, Australia





More information about the Qt5-feedback mailing list