Mark Rafn wrote:
AssertionError is right out. Assertions exist to make low-severity
bugs into
high-severity ones so you can find and fix them. They're not part of
an API
design.
I agree with your conclusion, but quibble over a detail. Assertions
do not "exist to make low-severity bugs into high-severity ones" at
all. They exist to verify pre- and post-conditions to ensure
algorithmic correctness. The bugs, if any, that are thus discovered
will have been "high-severity" bugs all along. Assertions exist to
make such high-severity issues visible to testers and developers
before they are visible to customers. Assertions usually are and
generally should be disabled in production, very much unlike exceptions.
The difference between exceptions and assertions is that they test for
different things at different points in the application lifecycle.
Exceptions handle anomalous data and like conditions at run-time.
Assertions handle incorrect algorithms at test-time.