If approval fails, the program should crash .
An assertion error means that the programmer made a fundamental mistake in understanding how this is possible for the program flow. This is development assistance, not production assistance. In production, exceptions can be handled because they can “happen”, while assertions should “never” work.
If you are in a camp that says, “Oh, but what if the statements do not work in production? I need to catch them.” then you are missing the point. Ask yourself, then, why are you not just throwing an exception (or otherwise handling the error)?
Generally speaking, a statement is not just an abbreviation for “if the condition is not met, the exception is an exception” (well, sometimes it’s operational semantics, but it’s not denotational semantics). Rather, a denial of approval means that the application is in a state that the developer does not even consider possible . Do you really want the code to continue to run in this case? Clearly (I would say) No.
user359996
source share