Home › Resources › Case Studies › Mitigate Risk of Automation Failure with Exception Handling
Mitigate Risk of Automation Failure with Exception Handling
![Mitigate Risk of Automation Failure with Exception Handling](/wp-content/uploads/2021/06/Mitigate-Risk-of-Automation-inner.jpg)
Without exception handling added into the development process for an automation the workflow will fail and the bot will crash during execution. It is a good practice for developers to handle both business and system exceptions during development as part of the end-to-end automation workflow system. Exception handling helps maintain the desired flow of the automation even when unexpected events occur while executing the automation workflow.
Let’s take an in-depth look at how to include exception handling within automations to mitigate risk.
There are two types of exceptions that developers will come across when executing an automation workflow:
- Business Exceptions: These exceptions are part of the business logic layer. This occurs when certain data needed to run the business workflow is missing or incomplete. For example, in a payment processing automation if the amount to be debited from an account is more than the balance of the account, a business exception will occur.
- System Exceptions: These exceptions are technical errors with an application or system the bot uses that occur during the execution of an automation. For example, in a payment processing automation if the payment application is not responding and the page fails to load, a system exception will occur.
For the sake of this exception handling example, we will be handling the FileNotFound exception which is a common system exception.
Almost every command in OpenBots v1.5 and newer contains an error handling property. This property allows developers to choose one of the three options “None”, “Report Error”, and “Ignore Error” as the outcome, if an error is received with that particular command while executing a workflow.
![](/wp-content/uploads/2021/06/Mitigate-Risk-of-Automation-1.jpg)
Every command that is expected to generate an exception is surrounded by a “try catch” block. As shown in the images below, the developer is trying to move a file from a source path to a destination path, however the file does not exist in the source folder. The move command in Openbots Studio would generate an exception of the “FileNotFound” type, where the developer inserted a try catch block to handle the exception. Developers can handle various types of exceptions through a catch block such as Argument Exception, DivideByZero Exception, IndexOutofRange Exception, and KeyNotFound Exception to name a few.
![](/wp-content/uploads/2021/06/Mitigate-Risk-of-Automation-2.jpg)
![](/wp-content/uploads/2021/06/Mitigate-Risk-of-Automation-33.jpg)
![](/wp-content/uploads/2021/06/Mitigate-Risk-of-Automation-4.jpg)
As a bonus tip, the developer can also print the error message with a Message Box activity, or log the error message in a log file with the log level as ERROR or FATAL.
![](/wp-content/uploads/2021/06/Mitigate-Risk-of-Automation-last.jpg)