You can use assertions to detect errors that may otherwise go unnoticed. Assertions contain Boolean expressions that define the correct state of your program at specific points in the program source code.
Reduce to use try/catch/finally to throw an exception instead of assertions.

Basic assertion helps you
1. Presents an overview of design by contract
2. Presents an overview of assertions
3. Shows how to roll your own assertion capabilities
4. Describes the new assertion facility
5. Shows how to use the new assertion facility
6. Offers guidelines for using assertions
7. Presents examples of how to use assertions

But you should watch the pitfall, too.

Reference:
1. Using Assertions in Java Technology
2. Programming With Assertions
3. Develop code using assertions

Advertisements