How to use the Global Exception Handler in UiPath
A brief guide on how to use the global exception handler in UiPath
What is it?
The Global Exception Handler is a type of workflow that determines the project's ability to cope-up with errors during its execution. The purpose of this workflow is to handle or manage the unmanaged errors that might come up during the process execution.
How to create a Global Exception Handler?
๐ธ To create a Global Exception Handler, navigate to New > Select Global Exception Handler.
Now, although we are allowed to created multiple Global Exception Handlers, only one can be set and used as primary handler. To change, right click on the required handler xaml and select Set as Global Handler option.
Understanding the default template
๐ธ The Global Exception Handler has 2 default arguments and it is built to take action based on these arguments.
The
errorInfo
argument: This is an in argument of typeUiPath.Activities.Contracts.ExceptionHandlerArgs
and this stores information about the error.The
result
argument: This is an out argument of typeUiPath.Activities.Contracts.ErrorAction
and determines the next set of actions to be taken by the process.
These arguments determine the project's behavior when an error is encountered and the next set of actions that has to be taken.
The action or behavior can be classified into 4 different categories:
Continue: The Continue option rethrows the occurred exception.
Ignore: The Ignore option ignores the exception and continues the execution from the next activity.
Retry: The Retry option retries the same sequence of activities when an exception is thrown.
Abort: The Abort option stops the execution once an exception is thrown.
This is how the default template is built in. However, we can modify the template to suit our needs by adding additional logging mechanisms or performing actions such as closing an application.
Try Catch vs Global Exception Handler
There can be misconceptions about Try Catch and Global Exception Handler being the same since both are error handling mechanisms and no, they are not the same.
Global Exception Handler | Try Catch |
Handles process level exceptions | Handles file level exceptions |
Expected to handle unmanaged errors such as arithmetic exceptions or index out of bounds exception | Expected to handle managed errors such as an unloaded webpage element |
Conclusion
In conclusion, the Global Exception Handler is a handy built in workflow that can be used as is or modified to handle any unmanaged errors that come up during the bot execution.
Thanks for reading the article. Please give it a like and share it with your friends. Got any questions? Let me know!
Cheers ๐