Opened 15 years ago

Closed 15 years ago

Last modified 5 years ago

#957 closed Feature Request (Completed)

Assert keyword or function

Reported by: Nutster Owned by: Jpm
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:


Could we add an Assert keyword of function that would break execution with an error message indicating the assertion that failed.


Assert($sABC > "")

If $sABC is empty (so the $sABC fails) the engine reports an error and exits the program.

AutoIt: Assertion on line 78 failed: $sABC > ""

Attachments (0)

Change History (3)

comment:1 Changed 15 years ago by TicketCleanup

  • Version deleted

Automatic ticket cleanup.

comment:2 Changed 15 years ago by Valik

Doesn't a function like this accomplish what you want?

; ===================================================================
; _Assert($bCondition, $sMsg, $bExit = True, $nCode = 0x7FFFFFFF, $sLine = @ScriptLineNumber)
; Asserts that a condition is true.
; Parameters:
;	$bCondition - IN - The condition that must evaluate to true.
;	$sMsg - IN - The message to display if the condition is false.
;	$bExit - IN/OPTIONAL - If true, the script is aborted.
;	$nCode - IN/OPTIONAL - The exit code to use if the script is aborted.
;	$sLine - IN/OPTIONAL - Displays the line number where the assertion failed.  If this value is not
;		changed, then the default value will show the correct line.
; Returns:
;	The result of the condition (Only valid when not exiting).
; ===================================================================
Func _Assert($bCondition, $sMsg, $bExit = True, $nCode = 0x7FFFFFFF, $sLine = @ScriptLineNumber)
	If Not $bCondition Then
		MsgBox($MB_ERROR, "Assert", "Assertion Failed (Line " & $sLine & "): " & @CRLF & @CRLF & $sMsg)
		If $bExit Then Exit $nCode
	Return $bCondition
EndFunc	; _Assert()

Note, $MB_ERROR is:

Global Const $MB_ERROR = 4096 + 16	; Standard error flags (Stop icon)

comment:3 Changed 15 years ago by Jpm

  • Milestone set to
  • Owner set to Jpm
  • Resolution set to Completed
  • Status changed from new to closed

Added in version:

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

as closed The owner will remain Jpm.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.