posted 17 years ago
Assertion is a very simple idea.
Basically, they are for exceptions that you believe SHOULD never happen but are not sure that they WILL never happen, and which you know will negatively affect the performance of your application if they DO happen. Assertions are not intended to be caught exceptions. They are used in circumstances in which you would not logically be able to react to the exception, and in which the exception should never occur anyway. The assertion immediately halts the application, so that if the exception ever occurs, there is 100% chance that you will know it happened, and you can then go about debugging it.
Assertions are typically useful for ensuring that changes in one section of the codebase will not cause code in other areas of the code base to fail in such cases as class invarients, and method pre or post conditions. Often, assertions will be ignored when the application is actually distributed.
- Adam