Jump to content
Sign in to follow this  

Predefined exceptions?

Recommended Posts


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.

Share this post

Link to post
Share on other sites

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

except on $readerror do

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.

Share this post

Link to post
Share on other sites

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

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 by aGorilla

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...