I was just looking over some code I had written sometime back and came across something that I thought would be a good area to use Assertions.
This has to do with using enums. Enums in c/c++/c# (and coming soon to Java in 1.5) are types which consist of some named constants. They are much preferable to just constants or "magic" numbers cause they are much clearer and are categorized.
Anyway, here's a simple ex of using it...
If your method takes a Color argument it can work with the values set in this enum.
private void ChangeBackground( Color color )
switch ( color )
// Change background to red
// Change background to blue
// Change background to green
// Don't do anything
This is fine, but what if sometime in the future someone adds a new value to Color? That switch statement will drop down to the default case. And you won't even notice it.
So it would be good practice to add an assertion in the default case.
Debug.Assert( false, "ChangeBackground(): Color " + color + " was not recognized" );
This is basically protecting yourself from your own code. In this example, it's not such a huge deal if it falls through to the default case... just that your newly added color won't be handled. But in other cases it might be more critical.