Sign in to follow this  
Followers 0
PaulIA

Checking for function errors

3 posts in this topic

I started using AutoIt several months ago for a unattended installation project for WinXP and have quickly become addicted. (I think I'm going to have to go to AA... AutoIt Anonymous) :) In writing several AutoIt projects, I find that I spend a lot of time writing code like:

Func MyFunc()
$rStruct = DllStructCreate("int;int;int")
if @Error then
  Display error message to user and return with error code
endif
DllStructSetData($rStruct, 1, 1)
if @Error then
  Display error message to user and return with error code
endif
DllStructSetData($rStruct, 2, 2)
if @Error then
  Display error message to user and return with error code
endif
DllStructSetData($rStruct, 3, 3)
if @Error then
  Display error message to user and return with error code
endif
.
.
.
EndFunc

As a result, a large percentage of my code ends up being error checking. Right now, to reduce this overhead, I've been "wrapping" the AutoIt functions that I use a lot like:

Func MyFunc()
$rStruct = _DllStructCreate("int;int;int")
_DllStructSetData($rStruct, 1, 1)
_DllStructSetData($rStruct, 2, 2)
_DllStructSetData($rStruct, 3, 3)
.
.
.
EndFunc

These wrapper functions simply call the original function, check the @Error or returned value for errors and optionally display an error message. This has worked well for me and reduces the amount of code by a ton.

So my question becomes: "Is there a better way to do this?" What I really was looking for in AutoIt, is the ability to tell AutoIt to report all errors itself (maybe a new feature that you could control with "Opt") or a user callback function like "onerror" that would get called when any of the built in AutoIt functions encounters an error.

Any appropriate comments/suggestions would be appreciated.


Auto3Lib: A library of over 1200 functions for AutoIt

Share this post


Link to post
Share on other sites



The way you are doing it is the best way to do it.

Share this post


Link to post
Share on other sites

Thanks for the replies. The ErrorCheck function is interesting. I'd never thought of wrapping the function calls that way.


Auto3Lib: A library of over 1200 functions for AutoIt

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  
Followers 0