Cannot access or create variables inside Catch block

Hi everyone,

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)

Thanks!

Hi @k.lange

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)?

Have you used it before in any other project?

No it’s not expected behaviour.

Is it a bug? - We would need more details like Studio version, System package version, and a sample project which recreates this issue.

For now, try restarting the studio, create a sample process and try to replicate the issue. If persists do let know!

I use UiPath Studio 2025.0.172 STS (I hope this is the version).

I tried to use variables in the catch block in another process and it worked there, so it seems to be a problem just in my project.

These are my dependencies:

@k.lange

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.

Hi,

I think the Studio version is 2025.0.172 STS.

You can see my dependencies in my other reply.

And here is my current scope:

“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…

If you have any other questions, let me know!

Thank you so much!

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?

Thank you!

@k.lange

Hmm, yes it shouldn’t be the case.

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?

Yes there is a difference. In the other project, there are the following packages:

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”…

@k.lange

can you share a screenshot of the variable panel?

These are my variables when I am in the try catch scope:

@k.lange

Not the ui package. Sorry I should have mentioned that it’s part of try catch, inlg if difference found in that one

But I noticed both of the versions are same in your both projects, so doesn’t seem like issue with package either

Can you try 1 thing?

Drag an assign activity in your catch block. Inside that do ctrl k to set variable and assign some value.

Are you able to do this simple thing inside catch?

No, I am not able to do this. When I press Enter to assign the variable, the error occurs.

This is the error message, that pops up:

“Fehler bei Variablenerstellung” = “Error during variable creation”

@k.lange

Please check below post, might be related.

Are you also using studioX?

Change the scope of variables to max.

I still cannot access/create variables there…

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.