[bt-devel] Programming Techniques
David White
bt-devel@crosswire.org
14 Mar 2002 21:18:54 +1100
On Thu, 2002-03-14 at 06:37, Holger Schurig wrote:
> > > AFAIK Qt overloads the new operator, but I'm not sure about this.
> > > And I never used exceptions, so I can't judge about this :)
> >
> > well, using exceptions is A Good Thing. Maybe we should discuss
> > BibleTime and exceptions sometime in the future :)
>
> Maybe the following info can be helpful in deciding if Exceptions are a
> good thing or not for Qt-Programs.
>
> I'm not even sure if your claim that new uses exceptions is true. When
> you look into the RPM spec files that make qt2 or qt3 you will see the
> "--disable-g++-exceptions" line. This is a tremendous memory saver for
> Qt. The switch translates to the -fno-exceptions command line option
> for gcc (and maybe to other things inside the Qt source code).
QT may not use exceptions, but that is a completely different thing to
new not throwing an exception. QT could possibly force new to not throw
bad_alloc, by changing its definition; however I would suggest that
enforcing such non-standard behaviour upon users would be A Bad Thing.
Further, presumably if new does not throw an exception, it returns null
on failure. This means, that for the application to be truly robust, and
to at least exit elegantly upon heap exhaustion, we would have to check
to see if new returns null every single time it is called. That would be
a painful and unrewarding process. If new throws bad_alloc on the other
hand, as the standard says it should, error handling is much, much
easier, and recovery from the exhaustion could even be attempted.
Also, the RAII technique is still a legitimate and powerful technique
for resource management, even if exceptions are not used. It is
universally accepted among the C++ elite as being *the* way to do
resource management in C++.
-David.
>
> Basically we don't ever get any exception out of Qt and we would use a
> different programming paradigma if we would use exceptions, wouldn't
> we?
>