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


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)

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

Catch e As Exception
throw e

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


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.


You can do that like this:


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