Handle Error
Handles an exception that might occur during the script runtime advancing to the next command or triggering a subroutine.
Command availability: IBM RPA SaaS and IBM RPA on premises
Description
Exceptions are unexpected event that can cause the bot to raise errors when it runs in a production environment or in debug mode. For more information on how to handle exceptions, see Exception handling. You can also see Debugging scripts and Start options when you handle exceptions in debug mode.
Script syntax
IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.
onError [--executenext(Boolean)] --label(String)
Input parameter
The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.
Designer mode label | Script mode name | Required | Accepted variable types | Description |
---|---|---|---|---|
Execute Next | executenext |
Optional |
Boolean |
Enable to run the next command if an error occurs during the script runtime. |
Subroutine | label |
Required when the Execute Next parameter is False |
Text |
Subroutine to trigger if an error occurs during the script runtime. |
Example
The Handle Error command ignore the error that is contained in the script and continue running the next command.
defVar --name firstValue --type Numeric
defVar --name secondValue --type Numeric
defVar --name result --type Numeric
// Handle an expected exception in the script. In this case, it advances to the next command.
onError --executenext
// Assigns values to variables to run a mathematical expression.
setVars --assignments "${firstValue}=2,${secondValue}=0"
// Calculate a mathematical expression based on a value provided before.
evaluate --expression "${firstValue}/${secondValue}" result=value
// Logs the operation's result.
logMessage --message "The operation\'s result is: ${result}" --type "Info"
The Handle Error command run the subroutine evaluateException
when the division went wrong. When it runs the routine to handle the exception, it recovers the script runtime instead of stopping it.
defVar --name firstValue --type Numeric
defVar --name secondValue --type Numeric
defVar --name result --type Numeric
// Handle an expected exception in the script. In this case, it advances to the next command.
onError --label evaluateException
// Assigns values to variables to run a mathematical expression.
setVars --assignments "${firstValue}=2,${secondValue}=0"
//Calculate a mathematical expression based on a value provided before.
evaluate --expression "${firstValue}/${secondValue}" result=value
//Logs the operation's result.
logMessage --message "The operation\'s result is: ${result}" --type "Info"
beginSub --name evaluateException
// Shows a message box indicating that the division went wrong.
messageBox --title "Division went wrong!" --text "${wdg:error.Message}" --icon "Error" --buttons "OK" --defaultbutton "FirstButton"
// Recovers the script runtime, running the next command.
recover
endSub