How to start back and beginning of loop if there is an exception

loop
studio
exception

#1

I have a Do While loop that is entering invoices online from a data table. If there is any error on an invoice, I want to skip the rest of the loop and start back at the beginning of the loop for the next invoice.

I already know how to use Try Catch. Is there any type of activity that can tell a loop to restart? It’s a pretty complex process and I’d rather not create a ton of If activities inside of each other if there is an easier way.

Thanks!


#2

Pseudo:

Do {
try {
//your processing logic
} catch (Exception ex) {
// your clean up code
}
} While i < dt.Length

Something like this?
Judging by your post, it seems like you already know what you need to do :slight_smile:


#3

Hi @atevis,

Take a look at the Retry Scope activity. Based on a condition it will retry the activities inside it and you may also set the amount of attempts there.

Or if you want to retry until every single invoice has been processed you could do something:

invoicesProcessed = False
Do 
  Try
    For each invoice in Invoices
        //process invoice
    End For  
    invoicesProcessed  = True
  Catch
  End Try
While Not invoicesProcessed

#4

Thanks @acaciomelo

I will give Retry Scope a go.

In the invoice entry Loop, there are about 15 fields that each can have their own errors (mainly if they don’t match exactly what is in the system. I was hoping I could make a Try Catch for each entry with their own error conditions and if any of them throw an exception, it would skip trying to enter all of the other fields and just go back to the beginning. Ideally there would be an activity that in an If statement (exception = true) would tell it to go back to a certain point, similar to the feature in the flowchart. I feel putting a flowchart in the Loop isn’t the answer (although it might be, I haven’t really thought about it). Maybe just having an If statement around each step in the Loop with Then being Exception = false might be the way to go.

Thanks for the help! I’ll test Retry Scope.