User Tools

Site Tools


assert_set_assumption_for_debugging_.htm
Navigation:  Language Reference > 2 - Program Source Code Format > Compiler Directives >====== ASSERT (set assumption for debugging) ====== Previous pageReturn to chapter overviewNext page

 

ASSERT(expression, [message] )

blk2blue.jpg

ASSERT Specifies an assumption for debugging purposes.
expression A Boolean expression that should always evaluate as true (any value other than blank or zero).
message An optional string expression (up to 64K) which displays in the dialog window.

The ASSERT statement specifies an expression to evaluate at the exact point in the program where the ASSERT is placed. This may be any kind of Boolean expression and should be formulated such that the expected evaluation result is always true (any value other than blank or zero). The purpose of ASSERT is to catch erroneous assumptions for the programmer.

If debug is on and the expression is false (blank or zero), an error message displays indicating the specific line number and source code module where the asserted expression was false. The user is invited to GPF the program at that point, which allows Clarion's post-mortem debuggers to activate.

If debug is off, the expression is still evaluated, but no error message is displayed if the result is false. To activate error messages in release build (debug is off), you can add the following project define to your application:

asserts⇒on

Example:

MyQueue QUEUE

F1       LONG

       END

CODE  

LOOP X# = 1 TO 10

 MyQueue.F1 = X#

 ADD(MyQueue)

ASSERT(~ERRORCODE(),'ADD MyQueue Error ' & ERROR())

END

LOOP X# = 1 TO 10

 GET(MyQueue, X#)

ASSERT(~ERRORCODE())      !This error only happens if the ADD above fails

END

!- Get Single Configuration Record

Access:CONFIG.Open()

SET(CONFIG)

ASSERT(~Access:Config.Next(),'Config record missing')

assert_set_assumption_for_debugging_.htm.txt · Last modified: 2021/04/15 15:56 (external edit)