Stop/Break execution when error occurs in Try Catch activity



Hi all!

I’m using Try Catch activity but what I want is if in Try Catch #10 an error happens, it stops all execution in that activity. How is it possible?




I don’t understand your question fully. If you are wanting to Break execution when an error occurs, then surround your entire sequence or Invoke with the Try/Catch which will cause it to exit outside and begin on the next part of your workflow; you can also use a Throw to force the error when desired to move to the Catch of your exterior Try/Catch.

To go even further, if the Try/Catch is in a State Machine, then you can set a destination condition for when the error occurs so it can go Exit applications or perform a retry; alternatively, you can enter a Switch box and based on a string or value set in the Catch (when an error occurred), you can go in the direction of the Exit applications and, again, perform a retry… so there are a few options there.

I hope this is helpful.




Hi Clayton, thanks for your anser.
I’m doing a process that find certain result but when it doesn’t find anything else it means that everything was found (here is when I want that the Exception in Try Catch activity Stops the execution of the robot). Is this possible?



Usually, when you do a process where you return certain results you will come to the end, which you can use an If activity or Decision box in a Flow Chart. This can tell your process to perform certain actions or exit. Or, if your process is going through a loop of items, then at the end of the loop it will stop processing those items and exit so not much is needed.

However, it sounds like when you get to the end of the results you are getting an exception and you would like to end at that moment. You can do this by surrounding the activity that throws the error with a Try/Catch, then in the Catch store a variable that identifies that the process is complete. You can then use that variable in a condition to exit a Do While loop or If/Decision activity to move on to exit your workflow, or if you are in a For loop you can use the Break activity.

I hope I helped answer your question.



Do you have an example of the Do While? I mean, how to “Stop execution” when variable value changes.
I was looking but nothing works for me.



Hi, I can’t really provide a sample but can explain what you can do.

I don’t know if it’s the best method but you can simply place the sequence that processes all your items inside the Do While, and use an If activity to skip over the remaining sequence

For example,


    Assign variable="COMPLETE"

  If variable.ToUpper<>"COMPLETE"
    remaining sequences

While variable.ToUpper<>"COMPLETE"

Therefore, you store your variable to “complete” when the activity throws an exception, causing the rest of your sequences to be skipped over, then it exits the Do While.

Let me also provide another method where using a nested Do While inside a Try/Catch


      Throw activity

  While True

Therefore, in this example, by throwing an error it skips out of the Do While. This method will require some additional handling because exiting out of the Do While when your items are complete is different than if a real error occurs.

Hope that helps!




Hi Clayton!

I did this

But it keeps doing the sequence inside Do While. The value in Try Catch 18 for Completado is 1 (because it finishes when cames to here) but the condition in do while is allowing to do de sequence inside it. What I’m doing wrong?




(I’m assuming your Do While is inside the “Try catch 18”)
There are two ways you can fix this.

  1. Remove the “Try catch 19” and just have the activity by itself so when the activity fails it goes outside of the Do While and into "catch 18"
  2. Inside the “catch 19” place the “Assign Completado = 1” from “catch 18”, so when the activity fails it changes the value to 1 and exits the Do While which uses “Completado = 0” (In this case you might not need “Try catch 18” at all unless you want to handle other Errors)

I hope I am clear and helpful.



It’s not working.
I did this:
I expect that it breaks and finish all process but not, it continues to next Try Catch regardless the condition. I can’t take my “Catch 19” out of the Try Catch because for other executions (with other parametrs) the process can break here (because it may finish here).




This looks correct. When the activity fails it goes to the catch and changes Completado to 1, then exits the Do While since condition is Completado = 0. Can you clarify what part is not working right? After it breaks the Do While it will continue to your outside Try/Catch “Try catch 19” and stay in the Try side of the Try/Catch until an additional error occurs. If you would like to skip the remaining of the “Try catch 19” you can use a If activity and use Completado <> 1 or ‘= 0’ as the condition so it only executes them if the process is not complete.



Thank you Clayton! It works with If Function :wink:


i’m also dealing same problem but in my case i’m working on for each file. when error occurs I want to go to the end of the current loop process. thanks in advance… @ClaytonM


Hi @Prakash_Raj

I don’t understand you fully so I’m just going to assume you want to jump to the bottom of a sequence that is inside of a For each ("…end of the current loop proces")

So you could do this various ways.
Ideally, you would have your process as a Flowchart that is inside the For each. However, if the process is not complicated, you could also use a sequence.

For each activity
    Process Flowchart or Sequence

You must also define what you mean by error, like do you mean an Element failed to click or type into, or do you mean an item was not found or not downloaded successfully.

If it is actually a bot error that you are wanting to capture and continue with the end of the loop process, then you would most likely need to surround a sequence of the activities you want to capture with a Try/Catch, so it can continue to the end of the loop of the current item. If it is something else like a file never got downloaded, then you can use an If activity or decision and check a condition with either a Boolean variable or something like File.Exists(filepath), then proceed to the part of the process that you wish.

It might look something like this:

For each


For each
    If condition

Those are just some ideas, and please clarify if I misunderstood.