
Robert Kawulak wrote:
There seems to be confusion between broken invariant and assignment of invalid value. The latter is handled by the error policy and it is its duty to prevent breaking the invariant. One of the ways to prevent it is throwing an exception, other ones are adjusting the value to be valid or ignoring the assignment. If the invariant gets broken, then it means there's something wrong either with your error policy, the constraint policy or the value type, because they do not fulfil the requirements of constrained class. So, as David has pointed out, broken invariant means that the programmer has done something wrong.
The confusion is all mine, I'm sure. However, I still do not see why a programming error should not be handled by an exception if it is possible. Of course some situations are so severe that the error is unrecoverable, but is that really the most common case with *detectable* programming errors? Regards, --> Mika Heiskanen