Encyclopedia > Assert

  Article Content

Assert

In computer programming, an assert is a function or similar programming language construct which immediately aborts program execution if a certain condition or expression is false (an assertion failure). In practice, it is used by programmers during development to check for potential errors or bugs; to aid in this the assert function of most languages may give information such as the filename and line number of the original source code. The functionality is called assertion.

For example, following the dynamic allocation of memory in a programming language such as C, a pointer may be checked to ensure that it is not null before proceeding. Without such an assertion, a reference may occur later that would cause an error.

Asserts are also sometimes placed at points the execution is not supported to reach. For example, they are placed at the default clause of the switch statement in languages such as C, C++, and Java.

Typically, all calls to assert are removed from production code since often using assert calls is considered bad programming practice. The function is primarily of interest to developers during the debugging process. That practice is often criticized using an analogy that it is like practicing swimming in a pool with a lifeguard and then going swimming in the sea without a lifeguard.

Java has supported asserts as a built-in functionality of the language since the release of version 1.4. In languages such as Java that also have built-in support for other types of exception handling, there is no reason to include asserts in production code. For this reason, Java's asserts explicitly support removal at compile time.

Compare with:



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
Northampton, Suffolk County, New York

...     Contents Northampton, Suffolk County, New York Northampton is a town located in Suffolk County, New York. As of the 2000 census, the ...

 
 
 
This page was created in 40.9 ms