Error Handling commands
try Try
Error handling block. The catch section runs when a command fails (catch --error:err puts the details in $err$); the finally section always runs afterwards, error or not (e.g. to close a browser or a workbook).
Block command: try … endtry with catch, finally.
Clause catch
| Parameter | Value | Default | Description |
|---|---|---|---|
--error | variable name | Variable that receives the error as a record: Message, Type, CommandLine, CommandType, Timestamp (e.g. --error:err, then $err.Message$) | |
--errormessage | variable name | Variable that receives only the error message | |
--errorline | variable name | Variable that receives only the failing line number | |
--errortype | one of business, system | Handle only errors of this type; the other type passes on to an outer catch. Every error when empty |
Clause finally
No parameters.
Examples
try
browser --action:open --url:"https://portal.example.com" --output:web
capture --browser:$web$ --action:click --dompath:"//button[@id='submit']"
catch --error:err
log --message:"Error occurred: $err.Message$" --level:error
mail --to:"admin@company.com" --subject:"RPA Error" --body:$err.Message$
finally
browser --browser:$web$ --action:close
endtry
try
if --condition:"$total$ <= 0"
throw --message:"Invoice $no$ has no total"
endif
catch --error:err
log --message:$err.Message$ --level:error
throw
endtry
retry Retry
Runs the enclosed commands again when one of them fails, up to --times attempts in all; with --until, also while that condition is false after them. After the last attempt the error goes on as usual (an enclosing try/catch handles it). Business errors (throw --type:business) are not retried.
Block command: retry … endretry.
Parameters
| Parameter | Value | Default | Description |
|---|---|---|---|
--times | number | 3 | Attempts in all, the first one included (3 = the first run and up to 2 more) |
--interval | number | 1 | Seconds to wait before the next attempt |
--until | condition | Also try again while this condition is false after the commands ran, e.g. $status$ = "done" (written like if --condition) |
Examples
retry --times:3 --interval:5
browser --action:open --url:"https://portal.example.com" --output:web
capture --browser:$web$ --action:click --dompath:"//button[@id='login']"
endretry
retry --times:10 --interval:30 --until:"$status$ = Ready"
restapi --action:get --url:"https://api.example.com/jobs/$jobId$" --output:job
set --name:status --value:$job.Json.status$
endretry
onerror Onerror
Task error handler: runs only when an error that no catch handled is about to fail the task (after the failure screenshot is taken), with the error in --error; then the run fails (or ends as completed with --then:complete). One per task, on the main level, usually at the end. Stopping the task does not run it.
Block command: onerror … endonerror.
Parameters
| Parameter | Value | Default | Description |
|---|---|---|---|
--error | variable name | error | Variable that receives the error as a record: Message, Type, CommandLine, CommandType, Timestamp (e.g. $error.Message$) |
--then | one of fail, complete | fail | After the handler: fail - the run ends as failed with the original error; complete - the error counts as handled and the run ends as completed (with a warning in the log) |
Examples
onerror --error:err --then:fail
log --message:"Failed at line $err.CommandLine$ ($err.CommandType$): $err.Message$" --level:error
screenshot --file:"C:\Botream\Errors\$System.ExecutionId$.png" --onerror:continue
mail --action:send --smtp:smtp.company.com --port:587 --from:robot@company.com --to:support@company.com --subject:"Robot failed: $System.TaskName$" --body:$err.Message$ --onerror:continue
queue --action:fail --item:$item$ --reason:$err.Message$ --onerror:continue
window --action:close --window:$erp$ --onerror:continue
endonerror
throw Throw
Raises an error: the nearest catch handles it (its --error variable holds the message), otherwise the task fails. Inside a catch section, without --message it passes the caught error on.
Parameters
| Parameter | Value | Default | Description |
|---|---|---|---|
--message | text | Error message, e.g. "Invoice $no$ has no total"; inside catch, empty re-throws the caught error | |
--type | one of business, system | business | business: a rule of the process is broken (bad data, missing approval) - never retried, the item is skipped. system: the application or network failed - retried like other technical errors |