How to continue to next row after getting an error withing a "For Each" row activity

Hi,

I’ve come across a problem with figuring out how to move onto the next row if my workflow gets an error/exception. I just need to move onto the next row but the only solution i could think of was using “if” activity with the whole workflow in it again, but using this logic I would be needing and infinite number nested “if” activities.

I just want to know what solutions have you guys used in order to get around this limitation.

1 Like

Hi,

I think whether you are using a rowcounter in a Do while or Flow Chart loop, or no rowcounter with a ForEach, both methods would involve a Try/Catch.

So, surround the Sequence where the error can occur with a Try/Catch. Then you can store a variable with a string or the exception if desired. For a ForEach, it can just do nothing in the Catch and it will move on to the next row when it loops again. For a Do while, it’s the same except you should be doing rowcounter=rowcounter+1 at the beginning so it will move to the next row. For a Flow Chart loop, you can use that variable you store in the Catch to feed it into a Decision or Switch box so you can restart the loop if there were more tasks to perform, and you should also be doing rowcounter=rowcounter+1 at the start of the loop.

I will also point out that if you need to exit the loop to do things such as close all applications then reenter the loop again (by having the Try/Catch surrounding the entire loop), then using a rowcounter is beneficial in that you can keep track of the current row you are on (technically you can also do a counter in a ForEach also)

Sorry for no visuals. I’m just typing out some suggestions quick.

Regards.

3 Likes

Hi,

if using For Each or While loop, you can just use Try… Catch activity to go to the next row, if any error/exception comes.

Just put a Try catch activity in For each/while loop, and put all the code within it. Now if any exception occurred in the flow, it will move to the loop again.

Thanks.

3 Likes

Thanks!

that’s really work…

thankyou so much…

While having a similar issue i have found an alternative that allows us to write errors as they occur and continue execution without stopping.

Within a For Each Row activity, initialize (re-use) boolean var, i.e. Assign ErrorFlag = False,

Then one can wrap the sequence or workflow that is to be executed within the For Each Activity with a Try-Catch Activity. On Catch, the flag is set to True (As an exception has been caught). On Finally block, an IF activity is used to write the status to the DT using the flag.

  1. ForEachActivity block
  2. a. Assign (Flag)
  3. b. Try-Catch
  4. b. (Try Block) Sequence
  5. b. (Catch Block) Assign Flag = True
  6. b. (Finally Block) If Activity
  7. b. i. (If Activity Block) - If Flag = True
  8. b. ii. Then write failure status to DT. Assign row.Item(Column Name on DT) i.e. Assign row.Item(“Status”) = Fail
  9. b. iii. Else write success to DT. Assign row.Item(Column Name on DT) i.e. Assign row.Item(“Status”) = Success
2 Likes

hey…can you help me on this plz?

hey. I have a process where, if condition is not satisfied error is thrown and need to take the next row item and do the same process.

The activities that I have used are:

Excel scope
for each
Then my process
IF

How to achieve it? Just putting try catch above IF will take the next row item?

Hi @amithvs,
You can use Continue Activity inside For Each loop, That got recently added in UiPath.

Alternate solution:
Excel Scope
For Each
Try Catch
Process to be done (If any error will occur, then it will go in catch, you can do exception handling there, and after that it will go and pick the next row)

1 Like

ok mate, wil try it. Do you have any sample files with this example??
with some exception handling scenarios!!!

CAN you share any demo??

Hey @caracevedo , I have 2 doubts: 1.) How to assign (Flag) in ForEachActivity Block
2.) Your 5th Point - How to assign Flag = True in Catch Block

Please share Demo