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.
@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
@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
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)
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
@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
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.
@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
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.diasBreak 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
@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
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