Error Codes for exception handling

Does UiPath gives error codes if a particular error/exception occurs?

Eg: Suppose if the network is down or slow, thus UiPath gives any particular error code for the same?

I was trying to handle different errors and exceptions but it seems a bit difficult without standard error codes.

If not, Is UiPath planning to include this in their upcoming versions?

The execution happens on .NET runtime. So Exceptions originate there.

Thanks @rajeev85 for the reply.
Does this means, we cannot get error codes for the exceptions originating at the run time?

Usually (and the best practise) to handle error is by the Exception Type not going by error codes. Can you provide a sample code where you tried handling errors?

I completely agree with you that best practice is to handle error by its type and not code but in our case it doesn’t help us.

For example- We get SelectorNotFound exception whenever the robot is unable to find the defined selectors but this error is generic as we can get SelectorNotFound exception in many cases like if application is unresponsive or actually the selector is not there and many more.

So, for such scenerios error codes are must.

SelectorNotFoundException is custom defined exception by UiPath. The HResult property may contain the error code (check here A lot of HRESULT codes... | Microsoft Learn) but I think this isn’t documented by UiPath hence using this in production is not advisable.

Do you really want to handle differently the cases: app is unresponsive, no network connectivity , invalid selector, whatever the case may I feel the Bot should log and halt and invite developer’s intervention.

1 Like

Thanks @rajeev85 for sharing the link. I will definitely look into it.

Yes, because for each case there are particular steps which are to be followed by the bot before halting.

Thanks @zimou13 for reply. But can you elaborate a little with one example if possible.

Hi @rajeev85 I saw the link and its very useful. Thanks for sharing. But I am unable to get any HResult Property in the exception thrown by the UiPath.

Here is an exception for SelectorNotFound
" UiPath.Core.SelectorNotFoundException: Cannot find the UI element corresponding to this selector: —> System.Runtime.InteropServices.COMException: Cannot find the UI element corresponding to this selector: at UiPath.UiBrowserClass.Find(String bstrSelector) at UiPath.Core.Browser.Find(Selector selector) — End of inner exception stack trace — at UiPath.Core.Activities.InvokeWorkflowFile.EndExecute(AsyncCodeActivityContext context, IAsyncResult result) at System.Activities.AsyncCodeActivity.System.Activities.IAsyncCodeActivity.FinishExecution(AsyncCodeActivityContext context, IAsyncResult result) at System.Activities.AsyncCodeActivity.CompleteAsyncCodeActivityData.CompleteAsyncCodeActivityWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)"

Could you please guide me over here how to use HResult Codes for classification?

@VipulBajaj
Use Try/Catch. And within the Catch the caught exception variable will have the HResult property. If variable is exception then it will be exception.HResult.

Thanks a ton @rajeev85. It proved very helpful for us.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.