Exception handling for For Each loop

Hi,

My bot searches account numbers, pulled from a row in an excel spreadsheet, in an application and selects the first result. However, sometimes there are no results. In this case, I want the bot to move on to the next cell in the row and continue searching. How/where can I implement exception handling to do this?

Might be helpful: I think the bot would run into an error when trying to switch to Window “Folder 0000” because it will not pop up if there are no results.

Thanks!

Hi @emeline.ahn you should put all actions that will fail in there are no results in the Exception Handling (“Try to complete” block), and the actions that the bot will need to perform in this case - in the “If an exception occurred” block. If the bot doesn’t need to do anything in this case and should start the loop for the next record, just leave this block empty.

Also, see this video tutorial on using Exception Handling

Hi @ashapkina
If I wanted to send an email to myself with the account number that couldn’t be searched, how could I do that in the “if an exception occurred” section? Because the actions under the “if an exception occurred” are not in the for each loop, I can’t type the text from the variable which stored the account number.

Thanks :slight_smile:

Hi,

My bot searches account numbers, pulled from a row in a spreadsheet, in an application and selects the first result. However, sometimes there are no results, so I’ve implemented exception handling. I want the bot to send an email to myself with the account number that couldn’t be completed, but because the actions under “if an exception occurred” are not in the for each loop, I can’t get the text from the variable which stored the account number. I’m not sure which action would get the account number from the exact row that couldn’t be completed, so that the number can be typed into an email.
Anyone know a fix? I’ve attached the screenshot.

Thanks! exception_snippet

@emeline.ahn you need to use Exception handling inside the For Each loop as shown below

image

@ashapkina I have put the exception handling in the for each loop, but every time it has to run the nested actions in the if an exception occurred section, it won’t go back to the try to complete process after it has sent the email. The bot just runs the process under if an exception occurred for every cell underneath the one it couldn’t execute. abc

It looks like it has an exception every time it tries to process the data.
Test your code: put it out of the exception handling for a while and see where the exception occurs.

@ashapkina When the code didn’t have exception handling it was working fine, it rarely ran into an exception.

Exception handling itself doesn’t affect the execution in any way, so it should be the same as without the exception handling.
Check the actions in the “Try to complete” block, perhaps, some of them are wrong.