So my activity is where I have a column in excel which contain links and when opened each of those links the page contains data tables which I would like to extract and past it in another sheet. I open each link using “for each row in datatable” and it works fine.
However, sometimes some of these links when opened on website might not contain tables and might be empty. during this time, it throws error
Source: WriteDataTable to Excel
Message: The source Data has no rows or columns.
Exception type: UiPath.Excel.ExcelException
Attached one screenshot. What I need is for this to skip that link when this error occurs and the loop continues to the new rows/of links in excel.
I think try catch might help here however, I am not sure how to use it, could you please help, I have attached few screenshots
Yes, using a Try-Catch block in UiPath can be a good approach to handle errors that might occur during the execution of your automation.
Here’s how you can use a Try-Catch block to handle the error you are facing:
Add a Try-Catch activity to your workflow, with the activities that read and write the data tables inside the Try block.
Inside the Try block, add a nested If activity to check if the data table is empty before writing it to the other sheet. You can use the DataTable.Rows.Count property to check the number of rows in the table.
If the table is not empty, write it to the other sheet as you are currently doing.
If the table is empty, use a Throw activity to throw a new exception. This will cause the workflow to jump to the Catch block.
Inside the Catch block, add a Log Message activity to log the error message, and another Throw activity to re-throw the same exception. This will cause the workflow to exit the Try-Catch block and continue with the next link in the loop.
Hey @Nitya1 , Thanks for the prompt response, really appreciate the help. Quick question,
I am using throw twice
(4. If the table is empty, use a Throw activity to throw a new exception. This will cause the workflow to jump to the Catch block.). Here is what I did is:
Step 1 If- condition- “DataTable.Rows.Count <> 0”
Step 2 Under Then- I added the write to excel activity
Step 3 Under Else- “I added Throw activity”
(5. Inside the Catch block, add a Log Message activity to log the error message, and another Throw activity to re-throw the same exception.). Here is what I did
Step 1 Under Catches I selected ExcelException under exception, added log message action under which I selected ‘Error’ from dropdown and under the message I wrote “Skip the step”+exception.tostring"
Step 3 Added another Throw activity just below the Log Message activity
My question is, what do I add or write under both these