4D v14.3ASSERT |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v14.3
ASSERT
ASSERT
The ASSERT command can be used to place an assertion in the code of a method. An assertion is an instruction inserted in the code that is responsible for detecting any anomalies during its execution. The principle consists in verifying that an expression is true at a given moment and, should the opposite occur, to cause an exception. Assertions are above all used to detect cases that should usually not ever occur. They are mainly used to detect programming bugs. It is possible to globally enable or disable all the assertions of an application (for example according to the type of version) via the new SET ASSERT ENABLED command. For more information about assertions in programming, please refer to the article concerning them on Wikipedia: http://en.wikipedia.org/wiki/Assertion_(computing) The ASSERT command evaluates the Boolean expression passed as a parameter. If the expression is true, nothing happens. If it is false, the command triggers the error -10518 and displays the text of the assertion preceded by the message "Assert failed:". You can intercept this error via a method installed using the ON ERR CALL command, in order, for example, to provide info for a log file. The command accepts an optional second parameter that can be used to provide a text that will be displayed in the error message instead of the text of the Boolean expression when it is false. Before carrying out operations on a record, the developer wants to make sure that it is actually loaded in read/write mode: READ WRITE([Table 1]) An assertion can allow parameters passed to a project method to be tested in order to detect aberrant values. In this example, a custom warning message is used. // Method that returns the number of a client according to its name passed in $1 |
PROPERTIES
Product: 4D
HISTORY
Created: 4D v12 SEE ALSO
Asserted ARTICLE USAGE
4D Language Reference ( 4D v12.4) |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||