- 12 Mar 2021
- 1 Minute to read
-
Print
-
DarkLight
-
PDF
Try / Catch Blocks
- Updated on 12 Mar 2021
- 1 Minute to read
-
Print
-
DarkLight
-
PDF
Try/Catch Blocks are helpful when you need to change the default handling of errors, perhaps to run an error handler, or to change the status shown to viewers of the execution.
By default, when an errors occur during the execution of a plan:
- the execution status is changed to failing
- the execution halts
With a Try/Catch block, if an error occurs in the main ("try") body, then the error handler ("catch") statements are run instead.
Example: Warn of Error
For example, a single failing statement in a testing environment will, by default, fail the job run. But because of the environment scope (testing) a warning might be more appropriate. This can be achieved by inserting a Try/Catch block to change the failing status to a warning and the job run will then continue.
Visual Mode
Text Mode (OtterScript)
Example: Corrective Action
Below a Try/Catch block has been created to start a Windows Service for Accounts
. Because the plan assumes the service already exists, however if the service doesn't exist the Try/Catch block will then run an ensure Accounts
operation to create the service and start the service it created. If both the start service AND the ensure service operations fail, the plan will fail as expected.