Jump to content

Error Handling Mechanism In AutoIT


Jigs
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 3 months later...
  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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