I’m running into an issue when working with a Try/Catch in UiPath Studio. Inside the Catch block, I cannot create new variables and I also cannot access existing variables that I’ve already defined in the Main scope.
For example, I created a variable screenshotBRE of type UiPath.Core.Image in the Main scope. In the Catch block (BusinessRuleException), when I press Ctrl+Space, no variables are suggested, and even if I manually type the variable name, Studio shows an error saying it’s not defined. I also tried wrapping the Catch contents inside a Sequence, restarting Studio, etc., but nothing worked.
It feels like variables are completely unavailable inside the Catch block. Is this expected behavior, a bug, or am I missing something in how UiPath handles variables in exception handling?
FYI: I want to take a screenshot and save it afterwards. Then I want to assign the image into the type System.Byte to write it into my datatable because I need the image in my word-file. (this works in the try block already)
That does sound like something you are missing at your end as you can create/refer variables inside catch for sure.
Can you please check your scope?
If you are using re-framework and have defined variable in main only, and trying to use that variable inside a workflow, please note you will have to pass it as an argument.
Also, to rule out that it’s not a bug, Which version of studio you are using?
And could you also share the dependencies you are using?
Is the first time you are trying this (variable inside catch)?
If it’s working for you in another project, then it’s not a bug.
Most likely you are creating variable in another scope and trying to refer somewhere else.
Or you have created variable in general business process scope and then trying to refer that in any of your inside workflows. Please note in this case, that variable needs to be passed to workflow as an argument.
Try to move level up from where you are able to see/find that variable created.
And then bring it to the level you are trying to use it.
“Anmeldeprozess” - I log in to the website.
“1. Testfall” - An order is created in 6 steps, and a screenshot is taken and logged for each step.
“Überprüfen mit Try & Catch” - The system checks whether the values have been transferred. If not, a BusinessRuleException is thrown.
When the exception is thrown, it should go into the catch block and there I want to do the exact same process to take the screenshot and save it into my datatable like in the 6 steps earlier, but in this block I cannot access/create variables…
This doesn’t work. I have already tried creating a variable at each level, but I cannot access any of them in the catch block. But apart from that, shouldn’t it be possible to create a variable with Ctrl + K?
You mentioned that you are able to create variables inside catch in another project, are you able to please compare dependencies versions of that project with your current project.
And if you find a difference, then bring your current project to that version of dependency and check?
I think the excel package doesn’t help to solve the problem. But in the other project, there is an older version of the ‘UIAutomation.Activities’. I changed the package in my main project but then most of my activities changed to “error activity”…
No I think I am using UiPath Studio because it is the Community Edition, but I am not quite sure about it.
I will rebuild my entire process. Then I will get rid of any legacy issues. Maybe it will work then. Currently, I have solved it differently, but I believe that try-catch will perform better in the long term.