YoungRacoon Posted April 21, 2008 Share Posted April 21, 2008 Hi! Is it possible to use in AutoIt something like "try-catch-throw" in C++?Use case: Someone tests a GUI application and wants to react on any unexpected behavior. Say, the menu item is missing when he tries to use _GUICtrlMenu_GetItemSubMenu. Or Select operation in ControlTreeView function was unsuccessful. Question: Can we catch these sutuations without "if-then-else" constructions around each AutoIt function?Desired behavior: Whenever a AutoIt function is unsuccessful, some kind of exception is getting thrown.Is it possible in one way or another? What would you suggest? Thanks in advance. Link to comment Share on other sites More sharing options...
weaponx Posted April 21, 2008 Share Posted April 21, 2008 http://svn.autoitscript.com/trac/ticket/188 Link to comment Share on other sites More sharing options...
YoungRacoon Posted April 21, 2008 Author Share Posted April 21, 2008 (edited) http://svn.autoitscript.com/trac/ticket/188That's pity. OK, there is no such an opportunity. And it is not planning. But what people do to implement something like that using current AutoIt possibilities? I mean, are there workarounds? Thanks. Edited April 21, 2008 by YoungRacoon Link to comment Share on other sites More sharing options...
martin Posted April 21, 2008 Share Posted April 21, 2008 That's pity. OK, there is no such an opportunity. And it is not planning. But what people do to implement something like that using current AutoIt possibilities? I mean, are there workarounds? Thanks.It isn't a problem in AutoIt IMO because the internal workings of AutoIt deal with exceptions and all you need to worry about is the return from a function and values of @error and @extended. It simply means that you have to do more checking than perhaps you would like but it also means that you can guard against the likely problems with just the standard coding methods. Try/except and try/finally are neat ways of handling problems which I am used to but they can be dealt with in other ways in AutoIt although maybe in a slightly more lengthy way. So, for a rather simple example, whereas you might want to write Try SomeFileIORoutine except on $readerror do CloseAllFilesAndComplain end in AutoIt you can have if SomeFileIORoutine = -1 or @error = 1 then CloseAllFilesAndComplain Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
aGorilla Posted April 21, 2008 Share Posted April 21, 2008 (edited) You could take it even further, and try to roll your own. Maybe something like this: Func _Try($act, $msg="", $fnc="") If (($act > 0) and not @error) Then return true If $msg Then msgbox(0, 'Error:', $msg) If $fnc Then Call($fnc) Return $act EndFunc If you do, please post it, I'd be interesting in seeing what you come up with, and/or what others can add to it. Edit: typo Edited April 21, 2008 by aGorilla Search AutoItScript.com via Google Link to comment Share on other sites More sharing options...
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