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.
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.
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.