Sign in to follow this  
Followers 0
willwatters

How to check if an error has occured

4 posts in this topic

I want to incorporate error handling in my code. So when i perform an automatic task I want to know if any errors occured and if so log this to a file. For example if i auotmatically open up an application or do a task i want to know if an error was generated and if so write this to a log file.

Thanks

Share this post


Link to post
Share on other sites



That depends on how the application you are automating shows errors. If it is a GUI application you can trap for an error window using the AdlibEnable() function. If it is a CLI application then you need to pipe the output to a text file and monitor the contents of the file. You may be able to use the Adlib to accomplish this also.

*** Matt @ MPCS

Share this post


Link to post
Share on other sites

many programs will give you an exit code, or you may get an error window that pops up. You can make your script look for these windows, and record the exit codes (if program gives them), and check to see if the program did what it was suposed to (file check maybe?)

Set your error text you want to $errorcheck and then

Just use a simple FileWriteLine("myerror.log",$errorcheck)


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

For the AdlibEnable() function I have used the following at the start of my script:

;/* check for unforeseen errors every 250 MS (i.e. checks for an error window to pop up unpredictably, etc)

AdlibEnable("myadlib")

Func myadlib()

If WinActive("Error") Then

MsgBox(48, "Error Found", "Unexpected error occurred")

Exit

WinClose("BAJI/CACI Jury Instruction Selector for Windows")

WinClose("Jury Instruction Selector")

WinClose("New Instruction Set")

WinClose("BAJI/CACI Jury Instruction Selector for Windows [instructions Not Saved]")

EndIf

EndFunc

Will this work (check for unforeseen errors every 250 MS (i.e. checks for an error window to pop up unpredictably, etc)) and is there any other code I need to enter here please?

Is there also a way of capturing the type of error in order to display it in the MsgBox?

Thanks for the great advice!

Edited by willwatters

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