Jump to content

When @error and @extended are set to 0


Recommended Posts

I am having an issue with the SetError and SetExtended functions. Essentially, I would like my function to be able to used in a Return statement and set the @error and @extended macros at the same time (e.g.

Return DebugOut($returnval, $errorval, $extendedval)
). But AutoIt is not allowing me to do that.

The following code

#include<Debug.au3>

Func Foo($indent="")
     ConsoleWrite($indent & "During call to Foo: expected 0|0, found " & @error & "|" & @extended & @CR)
     Return SetError(3, 4, "returning 3|4")
EndFunc

Func Bar($indent="")
     ConsoleWrite($indent & "During call to Bar - prior to calling Foo: expected 0|0, found " & @error & "|" & @extended & @CR)
     $result = Foo($indent & $indent)
     $holderr = @error
     $holdext = @extended
     ConsoleWrite($indent & "During call to Bar - after calling Foo: return=" & $result & ", found " & @error & "|" & @extended & @CR)
     Return Foo($indent & $indent)
EndFunc

SetError(1, 2)
ConsoleWrite("Prior to calling Foo: expected 1|2, found " & @error & "|" & @extended & @CR)
$result = Foo("..")
$holderr = @error
$holdext = @extended
ConsoleWrite("After calling Foo: return=" & $result & ", found " & @error & "|" & @extended & @CR)

SetError(5, 6)
ConsoleWrite("Prior to calling Bar: expected 5|6, found " & @error & "|" & @extended & @CR)
$result = Bar("..")
$holderr = @error
$holdext = @extended
ConsoleWrite("After calling Bar: return=" & $result & ", found " & @error & "|" & @extended & @CR)

Produces the this output:

Prior to calling Foo: expected 1|2, found 1|2
..During call to Foo: expected 0|0, found 0|0
After calling Foo: return=returning 3|4, found 3|4
Prior to calling Bar: expected 5|6, found 5|6
..During call to Bar - prior to calling Foo: expected 0|0, found 0|0
....During call to Foo: expected 0|0, found 0|0
..During call to Bar - after calling Foo: return=returning 3|4, found 3|4
....During call to Foo: expected 0|0, found 0|0
After calling Bar: return=returning 3|4, found 0|0

Note that whenever Foo() returns the @error and @extended codes are set. But when the call to Foo() is included in a Return statement (

Return Foo($indent & $indent)
) the @error and @extended values are lost. I don't know why this is happening. The documentation says

"When entering a function @error is set to 0" but this seems to be re-setting the values in Bar() between the time control returns from Foo()'s code and the use of that returned data in Bar()'s Return statement.

Any ideas, anyone?

Clive Pottinger

Victoria, BC

Link to comment
Share on other sites

Foo() is returning @error only to Bar()

When you execute this code

Return Foo($indent & $indent)

Foo($indent & $indent) is executed first

The return value of which is "returning 3|4"

Bar() then returns that, and @error is not set.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

The documentation also says:

This means that in order for @error to be set after a function, it must be explicitly set.

And you don't do SetError() in Bar().

Edit: Hi JohnOne

Edited by AdmiralAlkex
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...