Design by contract using assertions or exceptions? [closed]

The rule of thumb is that you should use assertions when you are trying to catch your own errors, and exceptions when trying to catch other people’s errors. In other words, you should use exceptions to check the preconditions for the public API functions, and whenever you get any data that are external to your system. You should use asserts for the functions or data that are internal to your system.

Leave a Comment