Sign in to follow this  
Followers 0
Jigs

Error Handling Mechanism In AutoIT

7 posts in this topic

Hi

I have used other tools for doing GUI Testing, but I am relatively new with AutoIT.

Normally in a language like C# we have a Try.. Catch block as a Error Handling Mechanism

OR Like

onerror GoTo <Function> Mechanism

What do we have in AutoIT?

Eg. So let say i have a script with following lines

Dim $var1

Dim $var2

$var1 = ShellExecute("outlook.exe")

$var2 = WinWait("Outlooks","",10)

.....

......

Other script commands

What i need is that if any of the line fails like ShellExecute or WinWait it should stop script execution and execute Error Function or return with 1 as ExitCode. Is this Possible.??

What i tried was to add this line on top.

$oMyError = ObjEvent("AutoIt.Error","MyErrorHandling")

but it never executed the MyErrorHandling function, becuase WinWait is error for me as string "Outlooks" will not exist.

Please Guide.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

You could experiment with @error and AdlibEnable... but you will also need logging to figure out where it fails

AdlibEnable("errorHandle")

...
...
...

Func errorHandle()
    If @error Then
        ConsoleWrite("Failure" & @CRLF)
        Exit 1
    EndIf
EndFunc

never tried it... worth experimenting

Lar.

Edited by LarryDalooza

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

To accomodate returns...

Global $success = 1
AdlibEnable("errorHandle")

$success = functionHere("stuff")
...
...
...

Func errorHandle()
    If (Not $success) Or @error Then
        ConsoleWrite("Failure" & @CRLF)
        Exit 1
    EndIf
EndFunc
Edited by LarryDalooza

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

Ugh... AdlibEnable does not work how I imagined. I thought it ran after every line of code or 250ms, whatever happened first or some crap like that.

NEVERMIND anything I've posted here... nothing to see here... move along.

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

AdlibEnable("errorHandle")

^ ERROR

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

AdlibEnable("errorHandle")

^ ERROR

Stick to your own thread, learn to read before asking and when you really need to ask a question formulate the question in stead of posting these types of posts. Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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