Jigs Posted December 1, 2009 Share Posted December 1, 2009 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 linesDim $var1Dim $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 More sharing options...
Administrators Jon Posted December 1, 2009 Administrators Share Posted December 1, 2009 Dim $res $res = 0 $res += ShellExecute("outlook.exe") $res += WinWait("Outlooks","",10) If $res < 2 Then MsgBox(0, "Some error", "") Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
LarryDalooza Posted December 1, 2009 Share Posted December 1, 2009 (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 December 1, 2009 by LarryDalooza AutoIt has helped make me wealthy Link to comment Share on other sites More sharing options...
LarryDalooza Posted December 1, 2009 Share Posted December 1, 2009 (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 December 1, 2009 by LarryDalooza AutoIt has helped make me wealthy Link to comment Share on other sites More sharing options...
LarryDalooza Posted December 1, 2009 Share Posted December 1, 2009 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. AutoIt has helped make me wealthy Link to comment Share on other sites More sharing options...
MikeTranser Posted March 9, 2010 Share Posted March 9, 2010 AdlibEnable("errorHandle") ^ ERROR Link to comment Share on other sites More sharing options...
Developers Jos Posted March 9, 2010 Developers Share Posted March 9, 2010 (edited) AdlibEnable("errorHandle")^ ERRORStick 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 March 9, 2010 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now