$ASSERTS: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 8: Line 8:


{{PageDescription}}
{{PageDescription}}
* If an error message is passed to the [[_ASSERT]] statement, it is displayed in the console window if [[$ASSERTS|$ASSERTS:CONSOLE]] is used.
* If this metacommand is in your program and any of the [[_ASSERT]] checks will fail, then the program will stop with an "_ASSERT failed" error.
* Detailed error messages passed to the [[_ASSERT]] statement will displayed in the console window, but only if [[$ASSERTS|$ASSERTS:CONSOLE]] is used.
 
;Note:* This metacommand is some kind of main switch to perform debug tests during developmet. Later just remove this metacommand to compile your program without debugging code, all the [[_ASSERT]] statements may remain in the code for later debugging sessions, they are simply ignored without this metacommand.





Revision as of 22:56, 30 April 2022

This metacommand enables debug tests with the _ASSERT statement.


Syntax

$ASSERTS
$ASSERTS:CONSOLE


Description

  • If this metacommand is in your program and any of the _ASSERT checks will fail, then the program will stop with an "_ASSERT failed" error.
  • Detailed error messages passed to the _ASSERT statement will displayed in the console window, but only if $ASSERTS:CONSOLE is used.
Note
* This metacommand is some kind of main switch to perform debug tests during developmet. Later just remove this metacommand to compile your program without debugging code, all the _ASSERT statements may remain in the code for later debugging sessions, they are simply ignored without this metacommand.


Availability

  • QB64 2.1 and up (QB64 Team)
  • QBPE 0.5 and up (QB64 Phoenix Edition)


Examples

Example
Adding test checks for parameter inputs in a function.
$ASSERTS:CONSOLE

DO
    a = INT(RND * 10)
    b$ = myFunc$(a)
    PRINT a, , b$
    _LIMIT 3
LOOP UNTIL _KEYHIT

FUNCTION myFunc$ (value AS SINGLE)
    _ASSERT value > 0, "Value cannot be zero"
    _ASSERT value <= 10, "Value cannot exceed 10"

    IF value > 1 THEN plural$ = "s"
    myFunc$ = STRING$(value, "*") + STR$(value) + " star" + plural$ + " :-)"
END FUNCTION


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link