In this session, we'll look at the basics of Error Handling in A2019 using the Try, Catch, and Finally Blocks. Remember: Beyond executing the task at hand, your bot's #1 responsibility is to not hard fail leaving a bot runner in a bad state; error handling is the best approach to always being in control of your bots.
Video Recap:
- Try
- The Try block is for the core code you want to execute.
- Should everything run smoothly here, the finally block would run next.
- Should things not run as expected, the catch block would run next.
- The Try block is for the core code you want to execute.
- Catch
- The Catch block is for code that should handle exceptions. This might include logging to a file, saving off a screenshot of the machine's current state, or even sending an email off to a support team.
- After the Catch block runs, the Finally block will execute.
- Finally
- The Finally block is for code that should execute whether an error occurred in this bot execution or not. This block might include things like writing out to an audit log, closing applications that may have been opened by the bot, or sending off an email to indicate bot run completion along with a status.
Bonus Tip
Did you know you can nest the Try-Catch-Finally blocks? Use a Try block with a Try block inside of it to carefully handle specific commands which may need to be handled with extra sensitivity.
Be sure to stay tuned to our Community for more Quick Tips!