Lets take a example that the Excel is opened and executing some Macro or Doing some basic activity. At that time some Exception occurs in System and closed the Excel .
By the Time some Unexpected errors can be catch using Try catch Block.
Or When you try to Open a file and Its not available in the space.
So as a Rule - WhatEver you Feel can break during an automation we keep it inside try Catch.
Example : Reading an value from an Excel file.
Exception can be - Excel File is Not available
Value is Not available.
So as a Developer - It depends on how you want to treat the above exceptions .
Excel File Not availalble - Either you stop the Bot or you raise a notification and continue to next part.
Now if we want to send notification and continue - we will keep the Read Excel in Try Block - this means we are telling uipath that this block of code inside may have some Exception.
Now Uipath will ask you - Okay so if I encounter exception - How should i handle it - Then you will go to catch block and specify how to handle it - Select the appropriate exception type in catch – if not sure of type … select system.exception - this will handle all exception.
Then inside the catch- Write Log - Send Email etc … This is send email/ write log and process will continue … to next steps …
Now if you still want to stop automation - you drag Throw activity inside catch - this will again throw the exception and process Breaks
okay - Second Scenario - You are looking for a value inside excel sheet
You did not get the value and you want to intimate someone and continue the proess… same way … put the read cell in try catch and inside catch - SendEmail - Here we have to continue the process … so we will not drag throw …
So Readcell will return you the value of the cell you are reading.
For eg : I am reading a cell and expecting a Name and the Name retrieved I am using in some other application , I will use the Readcell activity and store the output is a variable say strName.
So in some instances , if I do not receive a name , the next half of the automation will break and complete process stops.
Here , I will can put this thing in a try catch and in catch section … I send an email saying name was not found for this cell.
Also , alternative way would be to check if strname variable is not null or empty or whitespace - then only we invoke the other part of automation.