Use try catch to return to another part of the fluxogram

I Have a robot that executes some acts for each xml file at the especified path but some times this process go wrong. I was thinking if i can use try catch to solve this problem. The robot tries to execute the flux, if something go wrong it move the xml file to another folder and start again with the next file.

Is there a way to make it?

@guilherme.dias As like you mentioned use try catch for the process that you were doing. If the bot encounters any error while executing XML it switches to a catch block where you can use Move File activity to move the current XML to the other folder.Once after moved the file, loop back to run the next available XML

But how can i loop back to the beginning? I don’t know any activity or a way to do this

@guilherme.dias if you reading XMLs from the folder then you can use for each activity and starts processing each file enclosed in a Try catch. Please find the below sample workflow for better understanding (3.1 KB)

Use below link to get more info on for each activity

I can not make it work.

I have this loop wich get the xml files

this is the activity that usually fail

After it fails, the robot goes to catch flux, do the steps and go back to try finalize the activities in the end of for each activity instead of cancel the next activities and go back to the beginning of the for each (go to the next file)

hi @guilherme.dias

you must move all the activities which are below to the try catch inside the try field, so if all the process is correct the robot will take the file, perform all the activities and continue, if and error occurs, just move the file in the catch field and continue with the other file. Let me now if i understand you escenario

best regards!

1 Like

@guilherme.dias Please keep the click ‘MA’ activity that you were showing in the screenshot within the try block

  • Also, the complete code should inside the Try block. So, whenever the bot encounters exception it will go to catch flux and do the actions (Move file). In turn it will loop back to the try block in for each activity. This process repeats until processing of all files completes
1 Like

For some how when i do it the the robot does not work.

I’ve solved this putting the activity i know that could fail inside the try. In catch, it run some activities and then move the file to another path amd break. But i’ve put the for each inside a while loop that will continue run while existes files in the folder.

can you share your workflow please?

@guilherme.dias Please remove the break activity in the catch flux and run the process

Break activity allows the bot to come out of for each loop completely. That means bot can no longer loop back

That is what happened in this case : When an exception occured bot was entering in the catch flux and doing some actions (Move file) then it was coming out of for each completely since you are using break activity at the end

That is exactly what i want. I will explain

This robot get an xml file, read the properties and open a system to register it. The activity inside try flux don’t work if the xml was already registered, so the system shows an error message, then the robot goes to catch flux and take a screenshot of the error (for the future this screenshot will be sended by email), do the steps to come back to the beginning of the process and move the xml to another folder. So if the robot needs to use the catch flux, it means that i don’t need to continue the flow inside for each loop, because the activities inside it only works for xmls that are not registered.

That is why i have put the for each loop inside thw while loop and added a break inside catch.

Am I doing this in the right way? Or are there better ways to do it?

@guilherme.dias Break activity also breaking the while loop. That is why after break bot is not looping back any more. To avoid this follow the below steps:

  • Take assign activity and read all the files at once to the variable. Use this variable in for each
  • Avoid while loop, take for each and starts processing the files inside try catch
  • Don’t keep the break activity inside catch flux any more since it breaks the complete loop (while, for each)

This way you can get the expected process. Also, If any exception occurs bot enters into the catch and perform actions and it will loop back to get the other file

Note : To get the next file don’t need while, you can use for each. It will get next file and repeat the same steps

Follow the below attached workflow for reading the files into a variable (3.1 KB)

But when i try to put all activities inside the Try field looks like catch does not work. (look at the example below)

This robot must open a program and log on. (All activities to make it works are inside the try field)

Inside the catch field there is a log message activity. But look at the result


The log message inside catch field does not execute.

I’m using this flux as an example because the other one is to longer, but the same thing happens

@guilherme.dias Looks like you have run it in the debug mode. When you run in that mode it shows the exception details when any exception comes by highlighting the activity like below and the exceution pause

Then, should click on continue . Check below

Then, it will continue the process or next steps

or do this try to run the code in a normal way click on the drop down of debug file like below and choose run file. Now the execution will start and check the output once it ends

@ushu you’re right!! Now it is working, thank you for the help!! Now i’m going to remove the while loop from the other project and test again!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.