Get particular error line and message in try catch

hi all,

how to get particular human friendly error message the and error line no.

Line if the excel is not able to open, it should give general error, like unable to open the excel incorrect file name or file name not found and the error line no.

I don’t want any complex error message…as it’s no use. i want simple and to the point.

thanks,

Hi @balkishan

In your catch block, you can have a log message and then throw exception activity to throw a defined error message.

If you have your excel file name saved in a variable.

Then you can customize your error message like

“Excel interaction for file name: “+filenanevariablehere+” failed due to exception: “+exception.message

Also, could you share more details on what error line no are you looking to add? And why is it needed?

1 Like

Put your Excel Application Scope or Read Range inside a Try block and Catch the error and create your message. In the Catch block, catch System.Exception. Use a Message Box activity with a simple message.

“Unable to open the Excel file. Please check the file name or path.” & vbCrLf &
"Error at line: " & exception.StackTrace.Split({vbCrLf}, StringSplitOptions.None)(0)

If this is needful then mark it as SOLUTION

Happy Automation

Hi @sonaliaggarwal47 i want the generic one, i just gave an example,

it should be simple type, i am not aware which exception type we should choose. as ex.message giving whole history which am not interested and the line no.

strange, why UiPath don’t have a system defined variable to get the exception line no…

error line not priting… we don’t have system variable to get the error line no?

No there is not any variable which can give error line but you can see on which activity the error is encoountered for that you can use

“Unable to open Excel file. Please check the file name or path.” & vbCrLf &
"Error at activity: " & ex.Source

Instead of
“Unable to open the Excel file. Please check the file name or path.” & vbCrLf &
"Error at line: " & exception.StackTrace.Split({vbCrLf}, StringSplitOptions.None)(0)

If this is needful mark it as SOLUTION

Happy Automation

this doesn’t make any sense…if i have 1000 lines of code…how will i identify which line??

this is not a practical…approach…

You can use “UiPath.OpenAI.IntegrationService.Activities” to summarize the error message.

So there is no any approach to find the error line you have to remember where you have used that activity

Cheers