Ascend4nt Posted March 21, 2009 Posted March 21, 2009 (edited) Hi, I've noticed just recently that alot of my code breaks because of a problem with AutoIT's error return code. Try the following example: Func _ReturnErr() Return SetError(1) EndFunc Func _ReturnReturnErr() Return _ReturnErr() EndFunc _ReturnReturnErr() If @error Then ConsoleWrite("Error returned correctly"&@CRLF) Notice how it never writes anything to the console? Why is that? Shouldn't this work just as a 'Return SetError(1)' should? It doesn't make sense why the @error is cleared, when it should really return the correct @error code. If this is documented somewhere let me know please. Otherwise I will report it as a bug. This isn't acceptable behavior to me. Thanks, Ascend4nt *edit: fyi, I'm running AutoIT v3.3 Edited March 21, 2009 by ascendant My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
Developers Jos Posted March 21, 2009 Developers Posted March 21, 2009 Pretty sure that the @error is reset for each function: Remarks When entering a function @error is set to 0. Unless SetError() is called, then @error will remain 0 after the function has ended. This means that in order for @error to be set after a function, it must be explicitly set. This also means you may need to backup the status of @error in a variable if you are testing it in a While-WEnd loop. The extended parameter is optional. It is only provided as a way to set both @error and @extended at the same time. If only @extended needs set, then it is recommended to use the SetExtended() function instead. This means you need to set the error again in _ReturnReturnErr(): Func _ReturnErr() Return SetError(1) EndFunc ;==>_ReturnErr Func _ReturnReturnErr() Return SetError(_ReturnErr()) EndFunc ;==>_ReturnReturnErr _ReturnReturnErr() If @error Then ConsoleWrite("Error returned correctly" & @CRLF) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Moderators SmOke_N Posted March 21, 2009 Moderators Posted March 21, 2009 (edited) Not sure if localization has anything to do with it, however you can remedy the situation:Func _ReturnErr() Return SetError(1, 0, 0) EndFunc Func _ReturnReturnErr() _ReturnErr() If @error Then SetError(@error) Return EndFunc _ReturnReturnErr() If @error Then ConsoleWrite("Error returned correctly"&@CRLF) Edit: Or what Jos said, follows my thoughts on it anyway (The localization). Edited March 21, 2009 by SmOke_N 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.
Ascend4nt Posted March 21, 2009 Author Posted March 21, 2009 (edited) @Jos, Return SetError(_ReturnErr()) won't work for functions where the function being called is used for a return value, unless you call it twice, which is pointless (like this:) Return SetError(_ReturnErr(),0,_ReturnErr()) @SmOke_N, that is what I've had to do - but look how foolish it looks, when you are setting @error to @error. This is a dumb (though working) workaround - not that I mean dumb as in your implementation, but the fact that this is needed at all - and anyone looking at the code will be 'wth?!'. I think this needs to be requested - that if a function is using 'Return functionname()', that 'functionname()' should both set @error and return the value. Thanks guys for the help, Ascend4nt *note: I just realized the above code example would be foolish for a function that returns a value - you'll be setting @error to the return value haha Edited March 21, 2009 by ascendant My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
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