[Qt5-feedback] new Qt5 - great! - but: What about exceptions?
André Pönitz
andre.poenitz at nokia.com
Mon May 16 11:22:41 CEST 2011
On Friday 13 May 2011 21:02:30 ext szyk100 wrote:
> Hi all
>
> One of modern languages feature included in C++ are exceptions.
> Exceptions have mainly one advantage and only one real disadvantage.
>
> Advantage is: clear separation "fast path" and error handling - for me
> this is huge advantage and I realy like this feature. It is the same big
> leap in programming as invention "code modularization" concept. I
> suppose you think "who care about some excepitons", but we have only few
> modern concepts in C++ and rule "full backward compatibility" stops many
> great innovations (see: D or Python language features for comparision).
> Ignoring such great feature as C++ exceptions is ununderstandable
> self-limitation.
>
> The only real disadvantage you (Trols) mentioned some where on your
> pages is that executables will grow 20% with exceptions enabled. But as
> you known during last 6 years drives and memory modules grown enormusly.
> And I suppose that situation is similiar like with OpenGL - this is very
> common and maybe limited devices will disappear quickly from the market.
There are several other disadvantages of _C++_ exceptions.
- Throwing exceptions through "alien" chunks of code that are implemented
in other languages or using different compilers, sometimes even for the
same compiler with different complier settings is not guaranteed to work.
We do use such code even at the core of Qt for e.g. event loops.
- Exceptions practically belong to the interface to a class, yet there is
no way to properly document it "in code". Even if exceptions specification
would "work", a change in use in 3rd party code would influence Qt's
interface.
The only sane approach to exceptions in C++ is to not let them pass
module boundaries. And that's basically what we have already by just
saying "we don't create exceptions by our own, you can use them if
you want, or use 3rd party code that does, but it's your responsibility
to cope with what you get."
I can go on for a while, code generation is certainly a _very_ interesting
aspect (if _I_ had the time I'd push for using "new (nothrow)" whenever
possible. Including error checking that can yield much tighter code then
normal "new") but first and foremost:
- Qt code right now is not exception safe. "Fixing" that is a _huge_ effort.
You can easily sink a few months of work here. A few of the "maintainer
wanted" items take significantly less effort, so from my point of view any
free capacities you might have would be spent better otherwise.
> Other your argument (but emotional in this case) was "historical
> reasons" for not using exceptions. If we will still thinking like that
> we could not using C++ for historical reasons (WinApi and Xapi or OpenGL
> api) and stay with raw C language. With argument like that we can even
> stay away from concrete and steel and using only stone and wood just
> "for historical reasons".
Nice rant. Unfortunately, that's not the Realm of Ivory Towers here.
Andre'
More information about the Qt5-feedback
mailing list