On 8/24/2015 4:51 PM, Thomas Richter wrote:
> Am 24.08.2015 um 21:29 schrieb Victor Bazarov:
>
>> In case nobody else answers (and in case that you didn't know), the
>> "throw()" is the exception-specification for that member and it says
>> that the member function does *not* throw any exceptions.
My bad. Should have looked. The wording is "the function does *not*
allow any exceptions".
>
> Actually, I would rather say that the C++ compiler ensures that the
> function never throws. Actually, throw() is equivalent to
>
> try {
> .. function body ..
> } catch () {
> std::unexpected();
> }
>
> So there is an additional overhead included in using throw() because the
> compiler has to catch exceptions within functions marked as throw().
>
>> Same effect
>> can be achieved with keyword 'nothrow' or 'nothrow(/const-expr/)' if the
>> /const-expr/ evaluates to 'true' (only C++11 and later).
>
> You probably mean "noexcept"? Actually, that is not quite equivalent to
> throw(), because the former calls std::terminate() if an exception tries
> to leave the function (i.e. the compiler is not required to unroll the
> stack).
Yes, of course "noexcept" (was doing it from memory).
Here is what my copy of the C++11 Draft Standard says:
<<An exception-specification is
non-throwing if it is of the form throw(), noexcept, or
noexcept(constant-expression ) where the constant-expression
yields true. A function with a non-throwing exception-specification
does not allow any exceptions.>>