Jump to content

Checking for function errors


PaulIA
 Share

Recommended Posts

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
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...