Best way to catch error and restart workflow process?

I have a workflow that errors out usually due to external issue with the far side (or some other causes). The job will run correctly on retry or after some retries.

I’ve tried a few strategies for restarting but haven’t found the one that works quite the way I need it to. Originally I used If statements to check necessary elements and invoke the workflow file again if condition not met. This worked except once the invoke was down downstream portions in Main would be skipped and workflow exits. That meant necessary end of job data validations were missed etc.

I now have a flow, pass arguments out of the workflow files and if condition is false send back to beginning. This works well except I don’t have a good way to break out of workflow file and have the job continue with the flow. I tried terminate workflow which I hoped would only apply to the workflow file and not main (but appears to apply main which doesn’t help)

You can put your main script into a try catch, that handles whatever exceptions are thrown from it.

Then you can put whatever sequence the error occurs in, into a try catch, and place the try catch into a do while loop.

So it will execute, and if it fails, have it catch the particular type of exception that is thrown, and try to handle it. Use a boolean variable and a counter for your loop.

It would look like this in pseudo code. Let me know if you have any questions.


new Boolean itWorked = False;
new Integer counter = 0;
Do {
  Try {
           //Try to do Activity
           itWorked = True;
         }
       Catch (Exception)
                {
                    /*Do the activity again...or try searching for
                      something that indicates 
                      that the activity will fail...
                    */
                     If (//the activity was successful... )
                        {
                            itWorked = True;
                        }
                     Else
                       {
                           counter = counter + 1;
                       }
                }
         Finally
             {
                //Log Message("This is the " +
                 counter.ToString + 
                "Attempted. Did it work?...." +
                 itWorked.ToString);
             }
} While ( itWorked = False AND counter < 3  )

Couple of questions:

  1. I haven’t see anywhere to directly code in UI path
  2. I’ve tried try catch inside the workflow file and around the invoke workflow file and the behavior didn’t seem to do what I was explaining above.

If I were to try and adapt your model can I surround my invoke workflow files inside try catch and use throw inside the file to accomplish?

Technically, you can use Invoke Code, however it would not be applicable for you. And, I also think she was representing psuedocode, so you would need to just use her logic with UiPath activities.

Are you trying to develop a retry mechanism? Typically, if you need an item to attempt a retry because of some condition, then you would place a Throw inside the IF, so it goes to the Catch, then returns back to process the item again. If you want it to skip the item and not retry, then use a BusinessRuleException when you Throw it. Then, in your Catch, handle it accordingly.

You might also want other conditions such as File.Exists() conditions to make sure you are not performing tasks that have already been complete.

You could check out the REFramework Template found in Studio under “Start” and “New from Template”. This uses a State Machine, but each section is surrounded by a Try/Catch to handle the exceptions, then transition to each part accordingly.

Another thought approach on this I have used in the past is a Switch box inside the Try/Catch, so it can jump to any part of the process without needing to perform the task over again. Lately, I have not used this approach cause it complicates knowledge transfer.

If your intent, however, is not for a retry mechanism, then I think you would just want to use conditions to navigate your process accordingly.

I hope this helps with some other ideas.

Regards.

Maybe I am not explaining the flow correctly.

I have broken the process into two main parts

  1. Open and excel. Login to a plugin. Execute a macro.
    a. if the plugin has not loaded kill excel. clear bad plugins registry and retry (this is easiest done by just starting this segment again)
    b. if login / connection error start segment over

  2. check the output file exists. Check the output file is recently modified. Check cells in file say success. If any of above fail restart section 1 and continue to data check again. Cycle this x number of times to prevent infinite loop.

as to pseudo code doesn’t help in suing UI path since my issue is finding the activities that line up with coding the psuedo code. if that were it I would know how to do already.