Jump to content
prasad123

Error handling

Recommended Posts

prasad123

Hello All

I have to do an automation task which will repeat in a loop for the set number of count. This code is working properly.

Now the problem is that, sometimes an error window pops up. So I need to click OK on the error window.

The popping is extremely random. Sometimes it may not pop even after 20 cycles of execution, or sometimes it can pop 2-3 times in the same cycle.

 

Can anyone please suggest a basic format so that:

  • My code runs normally for the set number of cycles, if no error window pops at all during the entire execution
  • Whenever the error window pops, the code should click on its OK button and then return back to the execution of the main code. There should not be any pausing or abrupt termination of the main code.

 

Please suggest some basic structure or some special function or command names which can help achieve this.

 

Thanking in advance

 

Share this post


Link to post
Share on other sites
Floops

Couldn't you put something like this into your loop?

If WinExists("Error Window") Then
    ControlClick("Error Window", "", "[CLASS:Button; INSTANCE:1]")
EndIf

 

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

Which program do you automate? Most programs have an API to allow automation.

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
prasad123

Thanks for replying.

I know about WinExists and ControlClick.

 

But problem is I cannot put it straight forward in my code because the Error Window pops up randomly at any point of the code.

The most crude way will be to write this "IF block" after each and every line of the code, which is definitely not the thing to do.

I need something based on TRY CATCH.  Correct me if I am wrong.

I am not able to get the proper structure and format for it.

 

Share this post


Link to post
Share on other sites
Floops

I see, what about AdlibRegister() ? Might not be the prettiest solution but it's better than putting an if-statement on every line.

  • Like 1

Share this post


Link to post
Share on other sites
prasad123
2 minutes ago, Floops said:

I see, what about AdlibRegister() ? Might not be the prettiest solution but it's better than putting an if-statement on every line.

Oh .. never heard of this function before.

I will check in Help about this function in detail.

 

But why did you say that it is not the prettiest solution. Are you aware of any drawbacks of it which I need to take care of ?

Share this post


Link to post
Share on other sites
Floops

Because you are calling a function every x milliseconds. That doesn't guarantee that it runs after every line of code. You could set the interval very low but then that function gets spammed which could be CPU-heavy.

  • Like 1

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

×