I have Datatable with with few data rows and columns. This datatable is in the TRY block.
If there is a systemexception in any row in the TRY block, I want to flag that as exception and when the flow moves to the CATCH block , add it to a temporary datatable with, so that the overall process doesn’t stop and cases which were processes are retained and those with exceptions are moved to a new DT.
Assign activity: (Variable: dtOriginal) - Assign your original DataTable to this variable
Assign activity: (Variable: dtException)
Type: System.Data.DataTable
Value: (New DataTable).Clone
Try Catch activity:
Try
Sequence activity:
Assign activity:
To: (Variable: dtOriginal)
Value: dtOriginal.AsEnumerable.Where(Function(row)
Try
’ Your processing logic here
’ For demonstration, throwing a simulated system exception
If row.Field(Of String)(“YourColumnName”) = “ExceptionCase” Then
Throw New System.Exception(“Simulated System Exception”)
End If
Return True
Catch ex As Exception
Return False
End Try
End Function).CopyToDataTable
Catch
Sequence activity:
Assign activity:
To: (Variable: dtException)
Value: (dtOriginal.AsEnumerable.Where(Function(row) Not row.HasErrors)).CopyToDataTable
If you are iterating each row by using for each, then encapsulate the activities which are inside for each with Try catch activity.
In Catch block create System.Exception in that block use add data row activity which is failed in to a new datatable. If got any exception in a data row in try block then the data row values added to new datatable in Catch block. Then the bot will come out of Try Catch block and iterate the next datarow.
Step 1: Initialize DataTables* :
Create two DataTable variables at the start of your workflow: MainDT for the original data and ExceptionDT for capturing exception rows. Use the Clone method to ensure ExceptionDT has the same structure as MainDT .
Example code step 1:
MainDT = // Your DataTable with data
ExceptionDT = MainDT.Clone() // Creates an empty DataTable with the same structure
Step2: Iterate with Try-Catch* :
Use the For Each Row in DataTable activity to iterate over MainDT.
Inside this loop, wrap your logic within a Try-Catch block.
Example code for step 2:
For Each row in MainDT
Try
// Your processing logic for the row
Catch systemException As Exception
// Handle the exception (e.g., log the error)
Log Message: systemException.Message
// Add the row that caused the exception to ExceptionDT
ExceptionDT.ImportRow(row)
// Optionally, set a flag or update a column in ‘row’ to indicate an exception occurred
End Try
Next
Note:
1.Treat each row as a transaction. This means if you encounter an exception with a row, you handle it immediately within the Catch block and then continue to the next row.
2. * In the Catch block, add the problematic row to ExceptionDT using ImportRow.
Optionally, you can add additional information to ExceptionDT, such as the exception message or a timestamp
Hi @srinivasmarneni , I just want the row number in which the error occured in my catch, could you please guide me how to do that in a little detail pls.
By continuing the whole process, I meant the full RE framework. If the exception has occured I just need to report which all rows had an exception.
do you think a new column which updates if the row was success or failed would suffice ?
2… Modify Transaction Data* : Update your transaction data to include a new column indicating whether the row was successful or failed. This will help in identifying which rows encountered exceptions during processing.
Exception Handling Logic
Inside your Process.xaml workflow, after processing each transaction item, update the status column based on whether the processing was successful or not. If an exception occurs, mark the corresponding row as failed.
Example flow
If successCondition Then
’ Process transaction item successfully
’ Mark corresponding row as success
transactionData.Rows(transactionNumber)(“Status”) = “Success”
Else
’ Handle exception
’ Log exception details
LogMessage("Exception: " & ex.Message & ", Row Number: " & transactionNumber.ToString(), LogType.Error)
' Mark corresponding row as failed
transactionData.Rows(transactionNumber)("Status") = "Failed"