Exception has been thrown by the target of an invocation ! invoke code excel manipulation

Dim xlwb As Microsoft.Office.Interop.Excel.Workbook
Dim xlws As Microsoft.Office.Interop.Excel.Worksheet

Dim xlwb2 As Microsoft.Office.Interop.Excel.Workbook
Dim xlws2 As Microsoft.Office.Interop.Excel.Worksheet

Try

xlApp = New Microsoft.Office.Interop.Excel.ApplicationClass

xlwb = xlApp.Workbooks.Open(" ")
xlwb2 = xlApp.Workbooks.Open(vlookup_mappingFilePath + vlookup_mappingFileName)

xlApp.Visible = True
xlws = CType(xlwb.Sheets(report_sheetName),Microsoft.Office.Interop.Excel.Worksheet)
xlws2 = CType(xlwb2.Sheets(vlookup_mappingFileSheetName),Microsoft.Office.Interop.Excel.Worksheet)
xlws.Activate
xlws2.Activate

Dim rowCount As Integer = xlws.UsedRange.Rows.Count
Dim colCount As Integer = xlws.UsedRange.Columns.Count

Catch e As Exception
Console.WriteLine(e.Message)
throw e
Finally
xlwb.Save
xlApp.Quit()

End Try

I intentionally failing my code so that i could get a business exception from invoke code but i am unable to do that
how to throw BusinessRuleException from invoke code unable to do that if i am using full path “Uipath.Core.BusinessRuleException” then also it is going to that super class of exception that is System.Exception but i want if any error occur in my code it should be buisnessRuleEception…please

@Palaniyappan

Hi @divyanshu.innowise,

Business rule exception is something that happens when the data in the process is incomplete or missing. I don’t see you are missing in the code.

Check this post once:

if you see the code where i am opening the file I have done a mistake at opening the file the string is empty
My question is if any error occurs in invoke code then it is throwing System.exception but i want to throw Business Exception if you can attach the xaml file with example.

@HareeshMR

You can do that like this:

image

But I don’t know how to add it in the code.

thanks but this I know , this didnt solving my problem @HareeshMR

Can you explain the requirement? Will try to help you

@HareeshMR if i am opening any excel file and editing it through invoke code and while doing suppose user put a wrong path then it should throw business exeption not system.exception