So far I got the impression, that throw() makes most sense if
the function does something harmfull, but ensure to handle
everything.
Or doesn't do anything harmful, so there is nothing to handle.
The classic use of throw() is on a member function swap, where
the member function simply swaps pointers (which can't fail),
rather than doing any sort of deep copy (which presumably could
fail, with std::bad_alloc, if nothing else).
Rether than worrying about such low-level details, you really
want to start by studying the notions of exception safety, and
the different possible guarantees you can offer. Only once
you've understood what you're trying to acheve (and what you can
acheve) will the rules become understandable. (Try googling for
"exception safety guarantee", and look for anything written by
David Abrahams. For starters:
http://www.boost.org/community/exception_safety.html, although
that may already assume a certain knowledge.)
From what you wrote to dertop
<quote>
-- The function never throws anything. This guarantee is more
or less necessary in a few critical places if you want to
write exception safe code. In C++, it's expressed by using
the "throw()" exception specifier
</quote>
I get you as follows: The decision when to decorate with throw()
isn't dependent on whether the function body is covered by an catch
(...) or is harmless by nature. It depends on whether I have to be
exception safe or not.
It's a contractual guarantee. It depends on what you want to
guarantee for the client code. Including in possible future
versions. A throw() restricts the possible evolution of the
function, but allows certain uses in client code that wouldn't
be possible otherwise.
Exception safety is a larger issue. *All* code must be
exception safe, period. What it means to be exception safe,
however, depends on the application, and at the class level,
what guarantees you choose to offer (which is a design
decision).
If this is true, I have to read more on this topic to be able
do make this decision. Do you know some good readings on
this?
Most of what I know has come from discussions with David
Abrahams, in news groups. Herb Sutter has also written on the
subject at various times. Be aware that our understanding of
the issues has evolved. Some earlier writings by Herb and by
Tom Cargill paint a far more negative picture than what we now
understand (although these writings played an important role in
triggering our understanding).