Use variables from Main in GlobalHandler


I created a Main flow and a Global Handler.
When an error occurs, I want the Global Handler to send a mail with a variable from the Main flow.

For instance, I have three customers x - y - z, the robot loops through them and performs some actions.
Then an error occurs on customer y (y is stored in variable “varCustomer”).
Global handler needs to send a mail with the following text in body: "Error occured for " + varCustomer

Can anyone explain me how I pass the “varCustomer” variable from “Main” to “Global Handler”?

Thanks in advance for the help!


I would use a try catch and have the exception activity to use varCustomer in a send mail activity.

Thanks for your reply. That would be a solution indeed, but the application is a bit bigger than in the example. So I want to use a Global Handler, because otherwise I need to implement Try-Catches at multiple places in the code.

@Cedric_Nuyts Sorry about that. I’m not familiar with the Global Handler.

Hi @Cedric_Nuyts,
I want to do something similar. Did you found the solution?


It is not yet possible to use the variables of the main directly in the global handler.

But what I do now, is writing the variables I want to use in the global handler to a file (Notepad or Excel). Everytime the variables change, they get written to the file.
In the Global Handler, the first activity I do then, is reading out that file to get the correct variables.

1 Like

Bro, in Globalhandler, just use the following piece of code in any activity.
errorInfo.Variables(“var1”).ToString, replace the variable name “var1” according to your main.xml variables. that’s it, if you have any issue please let me know.


This works for string variables, how would you handle a Browser variable?

I didn’t get you, can you elaborate?

The way you described to pass variables to the global handler (errorInfo.Variables(“var1”).ToString) works only for string variables, I have a Variable of type UiPath.Core.Browser, and I need to pass it to the global handler so I could close the tab/browser when I have an error in the flow.
I know that I can use try/catch in the main xaml but I prefer to do this in the global handler, do you know of a way I could refer to this type of variable in the global handler?


can you plz explain it with screens as i am trying to make this but this error returned "Object reference not set to an instance of an object. "
Thanks in advance :slight_smile:

For this you could use something like this:

CType(errorInfo.Variables(“var1”), UiPath.Core.Browser). This will convert it to the correct type.