Share this post

Link to post

Share on other sites

RTFC 240

RTFC 240

Any function called (including Sleep) will immediately (that is, before executing the called function) reset @error and @extended to 0 automatically, so that the function can then generate meaningful error codes upon return.

Share this post

Link to post

Share on other sites

czardas 1,200

czardas 1,200

I believe SetError() and SetExtended() are limited to int-32. I don't understand what you say about Sleep(). Errors are automatically reset to 0 when you enter a function: Sleep() is a function. The best way to handle SetError() is to use it as a return command from a function.

Share this post

Link to post

Share on other sites

czardas 1,200

czardas 1,200

You can store as many error values as you like, for as long as you like, using different variable names or even an array of error values. You could even store multiple errors as single integer using bitwise functions. There are many possible solutions to your query.

Share this post

Link to post

Share on other sites

RTFC 240

RTFC 240

I fully support czardas's example in the direct case. When you're calling your own functions that may return errors, it gets slightly more complicated. In this example from my matrix computing environment (Eigen4AutoIt), I use SetError directly within a function body as early-out when various things go wrong:

Here @error=1 in a 32-bit environment (not supported by HighMem), and 2 if no valid pointer is obtained. If all is well the Return argument being the real (NB _HighMem, not _Eigen, note the different prefix) function call, @error and @extended from that call are parsed upwards to whatever routine called _Eigen_Release_ExclusiveAccess (which returns True if successful). This can also be chained, like so:

This second example is a so-called alias wrapper (exclusive access is controlled by a mutex, and since I always forget my own function names, I add tons of alias wrappers as mental crutches). Note how we collect whatever the true function returns in local variabe $tmp, and immediately afterwards, we parse the current contents of @error and @extended up the calling chain, preserving their status. Circling back to the original argument, if we wanted to do other stuff inbetween we'd have to collect those macro contents first:

Sign in

Similar Content

Hello World!!!
this is the first time I use Error checking and Im really confused with this, am I doing it correctly?.
I check the help file and came up with this
#include <MsgBoxConstants.au3>
;1st example
Local $hWndR = wtf(WinExists("[CLASS:CalcFrame]"))
If @error Then
MsgBox($MB_SYSTEMMODAL, "Error", "calculator does not Exist!!!")
Else
MsgBox($MB_SYSTEMMODAL, "Result", "calculator Exist!!!")
EndIf
Exit
Func wtf($hWndR)
If $hWndR < 1 Then
SetError(2);where did you get this "2"
ElseIf $hWndR > 1 Then
SetError(1); and this "1"
EndIf
Return $hWndR
EndFunc ;==>wtf
;~ 2nd Example
Local $hWndR = wtf(WinExists("[CLASS:CalcFrame]"))
If Not @error Then
MsgBox($MB_SYSTEMMODAL, "Error", "calculator does not Exist!!!")
ElseIf @error Then
MsgBox($MB_SYSTEMMODAL, "Result", "calculator Exist!!!")
EndIf
Exit
Func wtf($hWndR)
If $hWndR = 1 Then
SetError(2)
ElseIf $hWndR = -1 Then
SetError(1)
EndIf
Return $hWndR
EndFunc ;==>wtf
Please can someone enlighten me...