An assertion is a condition that you, as a programmer, expect to be unequivocally true at a given point in the program. Many programming languages give you a way to assert a condition, and you, as a programmer, can use assertions to find and diagnose many problems before they happen.
For example, if at a specific point in your program, you expect a variable called a
to be 0
, you can write:
assert(a == 0);
and if during runtime, a
is not 0
at that specific part of the program, you will get an artificial error, and the debugger will stop right there so you can diagnose your problem, and understand why a
is not 0
.
A very common assertion goes like
assert(some_pointer != NULL); // We already checked this before
In your specific example, a variable called pred_dir
is expected to be less than or equal than 2
. If you're getting an assertion error in there, it means that for some reason, pred_dir
was greater than 2
. Since the rest of the program is not expecting this, it makes no sense to keep on going, and the program will stop right there.
Please remember that assertions are a debugging aid to help you implement "sanity checks", and not as a way to display an error to a user. As such, you are encouraged to use lots of them when making your program, to make sure that all your assumptions about the state of your program are correct. If your program is correct, assertions should never stop the program.
Since assertions are a debugging aid, checking them makes no sense when you release your program for distribution to users. Therefore, many programmers turn off assertion checking when doing so. Many environments like Visual Studio automatically turn them off when creating a release build.
Check the wikipedia article, as it explains assertions in much more detail.
If an assertion is triggered on a released product, or a third-party library, it most likely means that there is an error in that program. If you are able to reproduce the problem, please report it to the author of the program.