require throw() and/or noexcept for contract broken handlers
Contract Programming Library for C++
Status: Pre-Alpha
Brought to you by:
lcaminiti
In order to be able to use contracts in C++11 functions declared noexcept I
would need that the contract handler are declared noexcept also, in
particular when the contract is broken from a destructor, which is often
declared noexcept in C++11.
Maybe the library can provide some specific set handlers that expect a
noexcept handler for the destructor context.
OK, I will do this when supporting C++11.
The same applies to throw() in C++03.
I would expect a different contract for contract broken from the constructor and the others ones.
I will comment more about this in a replay to Andrej comment.
summary changed from support broken handlers for throw() and noexcept to require throw() and/or noexcept for contract broken handlers
The contract broken handlers are noexcept, so that adding contracts don't
change the original prototype.
They will be when C++11 support is added (again, I'd prefer later but
I'm OK otherwise even if that will delay a possible release).
If you are allowed to release without C++11 support, it will be great if the documentation states clearly that the contract broken handlers can not throw. Otherwise, when moving to C++11, the C++03 usage will be broken. Even if you don't take care of C++11 features for the functions declaration, you could request that the contract broken handlers are noexcept using the Boost macro BOOST_NOEXCEPT, which is empty in C++03.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1962.html#failure-handler-functions
I think you don't want the handler setting function to throw given
that what you are setting is the handler itself which will affect how
you will handle a thrown exception (e.g., while evaluating a contract
assertion).
I agree that this function had better not throw. But...
You implement this function: you can implement it so that it does not throw
and guarantee that in the documentation, but you need not use "throw()"
syntax. By typing "throw()" your implementation does not throw less. But
you can make the function execute slower because now the run-time will also
have to check if your function throws (you know it doesn't - but the
compiler or run-time does not) and if so, call std::unexpected(), and so
on...
I understand than n1962 proposes it, but dynamic exception specifications
were not deprecated at the time it was proposed. Now it would probably be
proposed as noexcept(true).
Also, see this Boost guideline
http://www.boost.org/development/requirements.html#Exception-specification.