mwhidden Posted December 6, 2014 Posted December 6, 2014 The documentation for SetError() says "When entering a function @error is set to 0.", but it seems there are other circumstances when @error is also set to 0. For example, somewhere in this code, after MakeError() is called, @error gets set back to 0, even though no functions are entered after SetError(1) is called. Func PassThroughError() MakeError() EndFunc Func MakeError() SetError(1) EndFunc PassThroughError() ; Who set @error back to 0? MsgBox(1, "", "@error is "&@error)
Moderators SmOke_N Posted December 6, 2014 Moderators Posted December 6, 2014 The @error is only set from the last function that set it from the one that called it. It's not global throughout all functions. This may give you a better understanding. Global $gnError1, $gnError2, $gnError3, $gnError4, $gnError5 Func PassThroughError() $gnError1 = @error ; this will zero out @error MakeError() $gnError4 = @error ; this should zero out, there's no seterror for the return from this function EndFunc Func MakeError() $gnError2 = @error ; this will zero out @error SetError(1) $gnError3 = @error ; this is from seterror EndFunc PassThroughError() $gnError5 = @error ; this returns the seterror from PassThroughError only For $i = 1 To 5 ConsoleWrite("Error: " & Eval("gnError" & $i) & @CRLF) Next Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
mwhidden Posted December 6, 2014 Author Posted December 6, 2014 After reading your response, I thought at first that it was though each function has a local @error, and SetError() reaches up into the calling scope and twiddles the calling function's local @error. But that's not right because the change of @error is visible within the called function as well as the caller. So I'm guessing instead of setting @error to 0 when a function is entered (as in the docs), what actually happens is that @error is also set to 0 when each function exits, unless SetError was called in the scope of that function itself. Is that right?
Moderators SmOke_N Posted December 6, 2014 Moderators Posted December 6, 2014 Yes Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
kylomas Posted December 6, 2014 Posted December 6, 2014 Internal functions as well... seterror(5) ConsoleWrite(@error & @CRLF) ; "5" as set in previous command ConsoleWrite(@error & @CRLF) ; reset to "0" by previous command (consolewrite) Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now